Remove meta information in picture using "convert" without changing the colors of the picture - image

I have a problem using the tool convert (imagemagick) to remove metainformation of pictures to make them smaller for faster delivery in websites.
When I use the convert command with following parameters:
convert -format png -strip pic1.png pic2.png
then the converted picture is much more darker than the original one.
I also tried to require the colorspace of the original picture with:
convert -format png -colorspace sRGB -strip pic1.png pic2.png
but it's the same problem.
Has anyone an idea how to solve it?
These are the example pictures:
(Original) Pic1:
(Converted) Pic 2:

The problem is the installed version 6.7.7 of ImageMagick (Standard-Version of Linux Mint 17)
In version 6.4 and (said in comment) in version 6.9 it works.
So the 6.7.7 version is buggy in that case.

Related

ImageMagick adds thick horizontal lines to PNGs extracted from PDF

Edit July 7, 2017: Downgrading to ImageMagick 6.9.5 solved this problem, which may be Cygwin-specific. I still don't know the underlying cause.
I need to extract data via OCR from images in PDF reports published by Chicago Public Schools. An example PDF is here (NB: this link downloads the file automatically rather than opening it in the browser). Here's a sample image (from PDF page 11, print page 8), extracted with pdfimages -png version 0.52.0 on Cygwin:
I'd like to crop each bar into its own file and extract the text with OCR. But when I try this with ImageMagick (version 7.0.4-5 Q16 x86_64 2017-01-25 according to convert -version), using the command convert chart.png -crop 320x600+0+0 bar.png, I get this image, with horizontal lines that interfere with OCR:
Running pdfimages to extract to PPM format first and then converting to PNG while cropping gives the same result, as does round-trip converting the extracted images to SVG format with ImageMagick's rsvg delegate, and fiddling with the PNG alpha channel changes the line's colors from gray to white or black but doesn't eliminate them. I've found a workaround of round-trip converting extracted images through JPG (introducing ringing artifacts, which I hope are irrelevant). But I don't see why I should have to do this. Incidentally, ImageMagick introduces the lines to PNGs even if I run a null conversion convert chart.png chart.png, which ought to leave the image unchanged:
I have found other complaints that PDF software adds horizontal lines to images, but none of them exactly matches this problem. A discussion thread mentions that versions of the PDF standard somehow differ in their treatment of alpha channels, but my knowledge of graphics is too poor understand the discussion fully; besides, my images get horizontal lines added after they're extracted from the PDF, because of something internal to ImageMagick. Can anyone shed some light on the causes of the grey lines?
Using the latest ImageMagick 7.0.6.0 Q16 Mac OS X, I get a good result. As mentioned above by Bonzo, the correct syntax for IM 7 is magick rather than convert. The use of convert reverts to IM 6. Also do not use magick convert either.
magick chart.png -crop 320x600+0+0 +repage bar.png
If this does not work for you, then there must have been a bug in your older version of IM 7. So you should then upgrade.
Note also the +repage is needed to remove the virtual canvas

Convert command not working in windows

Installed ImageMagick-7.0.4-7-Q16-x64-dll.exe for resolving the issue of Tesseract facing problems with smaller font explained in this Stackoverflow question Is there any way to improve tesseract OCR with small fonts?
I ran the following convert command. But it still says invalid parameter.
C:\Users\rt\Desktop\Sample_Files>convert -resize 400% image5.jpg image5out.jpg
Invalid Parameter - 400%
and when I ran this
C:\Users\rt\Desktop\Sample_Files>where convert.exe
C:\Windows\System32\convert.exe
so just one convert.exe, I guess which belongs to windows convert.
I am missing something or something wrong with Tesseract or ImageMagick? can anyone help ?
convert is now replaced by magick to avoid clashing with Windows CONVERT.EXE.
identify becomes magick identify.
mogrify becomes magick mogrify. Likewise, animate, compare, compose and stream.
Or alternatively, to keep using the old command names, you must tick the Legacy box when installing ImageMagick.

AR face database : The original conversion of .raw files into other format

I have successfully downloaded and unzipped the .raw files from the set. But i am having problem with the convert command
$convert -size 768X576 -depth 8 -interlace plane rgb:m-001-1.raw m-001-1.bmp
As i am converting it is giving yellowish background image as seen in photo. But the image in AR face database with RGB format have white background.
Can anyone tell what is the problem?
the photo in raw format in database is of 24 bit depth.
The fact that the face is recognisable in its form indicates that you have the sizes and bit-depth and interlace correct.
The fact that it is yellow when it should be white indicates that the blue channel is "unhappy". If you delete the current blue channel, and duplicate the red channel and use that as blue, it comes out presumably closer to the original:
convert http://i.stack.imgur.com/knQkT.png -separate -delete 2 -clone 0 -combine result.png
My guess is that you have an old ImageMagick version and that you should probably avoid BMP format - maybe consider using NetPBM's PAM format instead - as it is easier to process.
NetPBM format link
To check your IM version use,
identify -version
Version: ImageMagick 6.9.2-4 Q16 x86_64 2015-10-29 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2015 ImageMagick Studio LLC

How to save 8-bit PNGs with ChunkyPNG or RMagick

I've been trying to save 8-bit PNGs (PNG8) using RMagick (http://rmagick.rubyforge.org/) and ChunkyPNG (https://github.com/wvanbergen/chunky_png) but have been unable to do so.
However the only time I can get it to work on RMagick is if the ImageMagick installation is based on the QuantumDepth of 8 rather than the usual 16. It is not possible to change this setting on the fly - the installation of ImageMagick has to be compiled with this setting.
Also setting the depth to 8 when creating the image or prefixing a format type when saving have no effect.
ie. img.write('PNG8:image.png')
Anyway I've had a look at ChunkyPNG and I really prefer to use this over RMagick - simply because it is pure Ruby and doesnt depend on ImageMagick. I can't save a PNG8 using that too.
I have to convert the PNG to 8bit afterwards using a graphics program -
My questions:
Is there a way of saving 8bit PNGs properly like it does on ImageMagick Q8 on a machine with ImageMagick Q16 installed?
Can anyone provide pointers as to do my own 4-bit encoder in ChunkyPNG or know of a way to save PNG8 with it?
Thanks in advance..
What exactly do you mean by PNG8? 8-bit grayscale, 8-bit indexed color, 3x8 bit RGB or 4x8 bit RGBA? All of these color modes are supported by ChunkyPNG.
By default, ChunkyPNG tries to determine the best color mode to save your image. You can overwrite it by providing an options hash to the save method:
image.save('filename.png', color_mode: ChunkyPNG::COLOR_TRUECOLOR)
# Or: ChunkyPNG::COLOR_TRUECOLOR_ALPHA
image.to_blob(color_mode: ChunkyPNG::COLOR_INDEXED, bit_depth: 8)
More info: https://github.com/wvanbergen/chunky_png/wiki

Preferred library and/or method of converting CMYK to RGB

Each month I get new CMYK and RGB images that shall be used on the web.
I had a script using a patched up ImageMagick doing this, but it got deleted. So I need to do it again, but it was hard last time.
How do you easily and quickly convert CMYK image files to RGB?
Like so:
convert CMYK.tiff -profile "RGB.icc" RGB.tiff
convert cmyk_image.jpg -colorspace
rgb rgb_image.jpg
The answer of g.b.1981 basically is correct (+1), but...
To make it work reliable, I found I had to add -type truecolor to the commandline:
convert cmyk.jpg -colorspace rgb -type truecolor rgb.jpg

Resources