I am running the following command:
compare -metric RMSE -subimage-search screenshot.png icon.png similiarity.png
which outputs:
0 <0> #617.0
because the icon.png is found within the screenshot.png
I want to grab that output and put it in a file, but using:
> result.txt
doesn't work (the file is empty)
How can I grab that result and put it in a file?
Just found the answer here: http://www.imagemagick.org/discourse-server/viewtopic.php?f=1&t=12618&start=0
The correct way:
compare -metric RMSE -subimage-search screenshot.png icon.png similiarity.png 2> result.txt
Compare outputs to stderr. Just redirect 2fd to file
compare -metric RMSE -subimage-search screenshot.png icon.png similiarity.png 2> result.txt
See I/O Redirects article. Using &> will redirect both stdout & stderr to your results file.
Related
I think I am missing the whole point with color profile. I assumed that sRGB was the implicit one for JPEG. But it does not seems to be the case or at least I am doing something wrong with my commands.
Let's take a random image from the web, and use jpgicc to make sure there is no profile:
$ wget https://cloud.githubusercontent.com/assets/1139185/23364727/3da8c474-fcce-11e6-9f39-7e074e78aa33.jpg
$ jpgicc 3da8c474-fcce-11e6-9f39-7e074e78aa33.jpg demo1.jpg
Now let's embed the sRGB.icm profile back in:
$ wget https://raw.githubusercontent.com/mikesplain/imagemagick/master/config/sRGB.icm
$ md5sum sRGB.icm
1d3fda2edb4a89ab60a23c5f7c7d81dd sRGB.icm
$ jpegtran -outfile demo2.jpg -icc sRGB.icm demo1.jpg
And finally apply sRGB.icm:
$ jpgicc demo2.jpg demo3.jpg
So in theory there should be no differences in between demo1.jpg and demo3.jpg, however:
$ compare -metric AE demo1.jpg demo3.jpg null:
106432
So what is the default color profile of a JPEG file if not sRGB.icm (1d3fda2edb4a89ab60a23c5f7c7d81dd) ?
This was an issue with the internal JPEG representation. When I do:
$ jpgicc demo2.jpg demo3.jpg
I decompress a JPEG into an RGB buffer and then convert it back JPEG. So in my case I should have done an extra step:
$ jpgicc demo1.jpg demo4.jpg
Then:
$ compare -metric AE demo3.jpg demo4.jpg null:
0
I have a DNG image and a cropped monochromatic version of the image. Both are generating the same file as the thumbnail when I run any of the below commands:
magick.exe C:\sample1crop.dng -resize 500x375 C:\crop-T.JPG
or
magick.exe dng:C:\sample1crop.dng -intent relative -sample 500x375> -strip -auto-orient -density 72 C:\crop-T.JPG
or
magick.exe convert dng:C:\sample1original.dng -thumbnail 500x375 -filter -auto-orient -density 72 C:\orig-T.JPG
As I am not allowed to upload the DNG files, thus I uploaded the images in hightail, sharing the link below: https://spaces.hightail.com/space/ThDEDYZVey
The generated thumbnail for both the cases:
I tried to get the thumbnail with exiftool as well:
exiftool -b -PreviewImage C:\86854\SLS\Issues\ART-73712\crop-T.JPG > C:\86854\SLS\Issues\ART-73712\thumbnail.jpg
exiftool -b -ThumbnailImage C:\86854\SLS\Issues\ART-73712\crop-T.JPG > C:\86854\SLS\Issues\ART-73712\thumbnail.jpg
but the resulting file seems corrupted. When I extract the exiftool metadata I see:
"ThumbnailTIFF": "(Binary data 42194 bytes, use -b option to extract)"
My requirement here is to get a generic cmd that provides a cropped monochromatic thumbnail similar to the original image.
Using this exiftool command, I was able to extract four images from those files.
You don't mention what OS or shell you're using but if you're using Windows PowerShell, it is known to corrupt binary data when piping or redirecting. Use CMD and you should be able to extract the images properly.
I have following images:
img01.png
img02.png
When I run tesseract img01.png img01.txt -l eng --psm 7 I get the texts
7.819 0 for the first image and
10.024 for the second one.
The second result is correct. However, in the first image, it is an o and not a zero.
How can I make Tesseract recognize o as o?
Update 1: I tried using the --oem 1 option as suggested in this answer (tesseract --oem 1 img01.png img01-ocred -l eng --psm 7), but it did not help.
Update 2: Binarizing the image using magick img01.png +dither -colors 3 -colors 2 -colorspace gray -normalize img01-binarized.png also didn't help. the binarized image looks like this:
You just need to enlarge the image twice the original then use tesseract.
wget https://i.stack.imgur.com/bSO87.png
identify -format "%wx%h" bSO87.png
40x20
tesseract -l eng --oem 3 --psm 6 bSO87.png stdout
7.819 0
convert bSO87.png -resize 80x40 bSO87.png
identify -format "%wx%h" bSO87.png
80x40
tesseract -l eng --oem 3 --psm 6 bSO87.png stdout
7.819 o
I have 100 images named img0.jpg to img99.jpg to be converted to a pdf file. problem is
convert img*.jpg out.pdf
adds pages in the order of 1,11,2,22,etc. how is order defined in imagemagick?
Either number your pages with zero-padded numbers like this so ImageMagick takes them in order:
img000.jpg
img001.jpg
img002.jpg
...
img098.jpg
Then your original command should work.
Or, have bash enumerate the files in order and feed the names into ImageMagick like this:
magick img{0..99}.jpg result.pdf
Or:
for file in img{0..99}.jpg; do echo $file; done | magick #- result.pdf
Or rename your files as per the first example above, but using Perl rename:
rename --dry-run 's/\D//g; $_=sprintf("f-%05d.jpg",$_)' f*jpg
Sample Output
'f0.jpg' would be renamed to 'f-00000.jpg'
'f1.jpg' would be renamed to 'f-00001.jpg'
'f10.jpg' would be renamed to 'f-00010.jpg'
'f11.jpg' would be renamed to 'f-00011.jpg'
'f12.jpg' would be renamed to 'f-00012.jpg'
You may have ls -v available to you, in which case you can try:
magick $(ls -v img*jpg) result.pdf
I have a bunch of PNG files named foo<bar>.png I wish to convert to TIF animation. <bar> is a number varies from 0 to 25 in leaps of five. ImageMagick place foo5.png last in the animation while it is supposed to be second. Is there a way, apart from renaming the file to foo05.png to place it in the right place?
If you have more input images than are convenient enough to type (say, foo0..foo100.png), you could do this (on Linux, Unix and Mac OS X):
convert \
-delay 10 \
$(for i in $(seq 0 5 100); do echo foo${i}.png; done) \
-loop 0 \
animated.gif
Simple and easy, list your images and sort them:
convert -delay 10 -loop 0 $(ls -1 *.png | sort -V) animated.gif
You just give the order of your PNG files as they should appear in the animation. Use:
foo0.png foo5.png foo10.png foo15.png foo20.png foo25.png
instead of
foo*.png
After all, it's only 6 different file names which should be easy enough to type:
convert \
-delay 10 \
foo0.png foo5.png foo10.png foo15.png foo20.png foo25.png \
-loop 0 \
animated.gif
You can use "find" with "sort":
convert -delay 10 $(find . -name "*.png" -print0 | sort -zV | xargs -r0 echo) -loop 0 animated.gif
Even easier than ls and sort is to use the built-in -v option of ls:
convert -delay 10 -loop 0 `ls -v *.png` animated.gif
with `...` being executed instead of interpreted as string.
Or if you know a bit of python, then you can easily leverage the help of it from python shell.
Hit up python shell by typing python in your terminal. And apply following magic spells-
# Suppose your files are like 1.jpeg, 2.jpeg etc. upto 100.jpeg
files = []
for i in range(1, 101):
files.append('{}.jpeg'.format(i))
command = 'convert -delay 10 {} -loop 0 animated.gif'.format(' '.join(files))
from subprocess import call
call(command, shell=True)
Your job should be done!
Actually, you can do something like:
convert $(ls -v *.png) animated.gif