I installed imagemagick for Windows from official site. I am trying to generate a diff image from two PNG images using ImageMagick. I am using following command:
compare file2.png file1.png -compose Src "diff.png"
But command exits with EXIT code "1". When run with -verbose flag, below message gets printed.
Image:file2.png Channel distortion: Undefined
I searched google for possible reason, but haven't found any answer. There is official ImageMagick documentation on distortion, but that is too wide and technical (and I am a novice).
Any idea why this message is thrown by imagemagick utility?
There is no real error. That message comes up when you do not specify -metric XXX with compare and take the default. The exit code 1 is what ImageMagick produces on success, I believe. See if you have an output file called diff.png. If you add -metric rmse, for example, you should not get that message. If I run the following without -metric XXX, I get:
compare -verbose lena.png lena.jpg -compose src diff.png
lena.png PNG 256x256 256x256+0+0 8-bit sRGB 118327B 0.010u 0:00.004
lena.jpg JPEG 256x256 256x256+0+0 8-bit sRGB 31640B 0.000u 0:00.002
Image: lena.png
Channel distortion: Undefined
lena.png=>diff.png PNG 256x256 256x256+0+0 8-bit sRGB 3c 1322B 0.130u 0:00.039
So it works fine. The message is telling you that it does not know which metric to use to give you difference statistics. I am not sure what it uses to generate the output. The term distortion may be a poor choice and perhaps should have been difference statistics.
If I add -metric rmse, then I get:
compare -verbose -metric rmse lena.png lena.jpg -compose src diff.png
lena.png PNG 256x256 256x256+0+0 8-bit sRGB 118327B 0.010u 0:00.004
lena.jpg JPEG 256x256 256x256+0+0 8-bit sRGB 31640B 0.000u 0:00.001
Image: lena.png
Channel distortion: RMSE
red: 810.821 (0.0123723)
green: 658.701 (0.0100511)
blue: 945.653 (0.0144297)
all: 813.547 (0.0124139)
Similar or same resulting image, but now the compare scores are reported since a specific metric is specified.
See the section about comparison statistics here
I am being stuck at some image editing using bash commands.
I have 414 images labelled 1file.png 2file.png ... 414file.png. To each of these I would like to add the number, which is already present in the name. The goal is to create a .gif which will show the counts of images in one corner counting up. (Creating the .gif using convert * result.gif works)
The problem is it will not add my number in the image but literally print $i. Does somebody know how to read in the loop variable?
I have tried:
for i in {0..9}; do
convert -pointsize 80 -fill black -draw 'text 1650 400 "$i"' "$i"file.png "$i"file.png;
done
Many thanks in advance.
Problem solved:
for i in {0..1}; do
convert -pointsize 80 -fill black -draw 'text 1650 400 '\"$i\"'' "$i"file.png "$i"file.png;
done
Converted the PDF file into .tiff which is pretty straightforward
convert -depth 4 -density 300 -background white +matte eng.arial.pdf eng.arial.tiff
Then train tesseract for the .tiff file -
tesseract eng.arial.tiff eng.arial batch.nochop makebox
Then feed the .tiff file into tesseract -
tesseract eng.arial.tiff eng.arial.box nobatch box.train .stderr
Detect the Character set used -
unicharset_extractor *.box
But I am getting this error -
unicharset_extractor:./.libs/lt-unicharset_extractor.c:233: FATAL: couldn't find unicharset_extractor.
And it also happening for mftraining and combine_tessdata as well.
UPDATE
Ran unicharset_extractor on single box file and still doesn't work.
And it is not only with this command but also with mftraining, cntraining and combine_tessdata.
I am trying to read and write jpegs wth Adobe RGB colorspace in OpenCV. OpenCV assumes the jpeg has sRGB colorspace and when displaying or writing to file, the image loses some of its color intensity. I found this intensity loss was due to colorspace difference by answers given to my previous question.
Is there anyway I can make OpenCV to read Adobe RGB colorspace without casting it to sRGB?
Some information that is hopefully useful for anyone looking for a work-around for dealing with ICC and other profiles...
You can see what profiles are present in an image using ImageMagick which is installed on most Linux distros and is available for macOS and Windows. In the Terminal, or Command Prompt on Windows, run:
magick identify -verbose frog.jpg | grep 'Profile-.*bytes'
Profile-icc: 578 bytes
That tells you this image has a 578 byte ICC profile embedded.
If you are on Windows and don't have grep, you can equally use the following, though you may need to double up the percent sign, or prefix it with a caret (^) or somehow escape it:
magick identify -format "%[profiles]" frog.jpg
icc
You can extract that profile from the image, using this command:
magick frog.jpg frog.icc
And, you'll get a 578 byte ICC profile:
ls -l *icc
-rw-r--r-- 1 mark staff 578 24 Apr 10:36 frog.icc
You can check that the profile looks correct using the file command:
file *icc
frog.icc: ColorSync color profile 2.1, type ADBE, RGB/XYZ-mntr device by ADBE, 560 bytes, 11-8-2000 19:51:59 "Adobe RGB (1998)"
You can apply that profile to some other file like this:
magick other.jpg -profile "icc:frog.icc" otherWithProfile.jpg
Once you have extracted the profile using the above method, you can apply it to an image that you plan to use with OpenCV using PIL/Pillow's ImageCMS Module.
For that, I think you need to use these steps or something very similar, though I have not tested it:
from PIL import Image, ImageCMS
import numpy as np
# Open frog with PIL/Pillow
im = Image.open('frog.jpg')
iccp = PIL.ImageCms.getOpenProfile("profile.icc")
rgbp = ImageCms.createProfile("sRGB")
icc2rgb = ImageCms.buildTransformFromOpenProfiles(rgbp, iccp, "RGB", "RGB")
result = ImageCms.applyTransform(im, icc2rgb)
You should then be able to convert the resulting image to a Numpy array that OpenCV can work with using:
OpenCVim = np.array(result)
and remember to then convert from RGB ordering to BGR with cv2.cvtColor().
Rather than detect and extract the ICC profile with ImageMagick, you could equally use PIL/Pillow like this:
from PIL import Image
im = Image.open('frog.jpg')
# Now look at "im.info"
{'jfif': 257,
'jfif_version': (1, 1),
'dpi': (72, 72),
'jfif_unit': 1,
'jfif_density': (72, 72),
'icc_profile': b'\x00\x00\x020ADBE\x02\x10\x00\x00mntrRGB XYZ \x07\xd0\x00\x08\x00\x0b\x00\x13\x003\x00;acspAPPL\x00\x00\x00\x00none\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xf6\xd6\x00\x01\x00\x00\x00\x00\xd3-ADBE\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ncprt\x00\x00\x00\xfc\x00\x00\x002desc\x00\x00\x010\x00\x00\x00kwtpt\x00\x00\x01\x9c\x00\x00\x00\x14bkpt\x00\x00\x01\xb0\x00\x00\x00\x14rTRC\x00\x00\x01\xc4\x00\x00\x00\x0egTRC\x00\x00\x01\xd4\x00\x00\x00\x0ebTRC\x00\x00\x01\xe4\x00\x00\x00\x0erXYZ\x00\x00\x01\xf4\x00\x00\x00\x14gXYZ\x00\x00\x02\x08\x00\x00\x00\x14bXYZ\x00\x00\x02\x1c\x00\x00\x00\x14text\x00\x00\x00\x00Copyright 2000 Adobe Systems Incorporated\x00\x00\x00desc\x00\x00\x00\x00\x00\x00\x00\x11Adobe RGB (1998)\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00XYZ \x00\x00\x00\x00\x00\x00\xf3Q\x00\x01\x00\x00\x00\x01\x16\xccXYZ \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00curv\x00\x00\x00\x00\x00\x00\x00\x01\x023\x00\x00curv\x00\x00\x00\x00\x00\x00\x00\x01\x023\x00\x00curv\x00\x00\x00\x00\x00\x00\x00\x01\x023\x00\x00XYZ \x00\x00\x00\x00\x00\x00\x9c\x18\x00\x00O\xa5\x00\x00\x04\xfcXYZ \x00\x00\x00\x00\x00\x004\x8d\x00\x00\xa0,\x00\x00\x0f\x95XYZ \x00\x00\x00\x00\x00\x00&1\x00\x00\x10/\x00\x00\xbe\x9c\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'}
Here's the frog.jpg image:
Keywords: Python, ImageMagick, image, image processing, profile, ICC profile, extract, insert, apply, transform, PIL, Pillow, OpenCV, CMS, pyCMS.
I'm using tesseract v 3.02
I have the following image
Download Image (right click -- save link as)
I would like to get the text from it. I'm using tesseract for the purpose.
When writing this command:
tesseract cropped.png tess -psm 7
The result I get is "suackea I 30 10193020 NL 3 e 1 64 :23 23% 34% 120". While the end is ok, the beginning is incorrect. The expected result is:
"Strackea III €0.10/€0.20 NL 6 6 1 €4 €23 23% 34% 120"
I have tried to do some transformation using imageMagick before tesseract to get an image with text written in black on a white background:
convert cropped.png -fuzz 28000 -fill black -opaque white cropped.png
convert cropped.png -fuzz 25000 -fill white -opaque rgb(118,118,118) cropped.png
The resulting image is
Download Image (right click -- save link as)
tesseract cropped.png tess -psm 7
but the result is the same.
What transformation or other command line tool would you use to recognize the text correctly ?)
The font the text is written in is Microsof Sans Serif