prevent black and white image auto convert to grayscale image - imagemagick

Start from ImageMagick 6.8, it will auto convert a black and white image(RGB) to be grayscale, which will make the altered image to be lighter than the original one. In ImageMagick 6.9, we can turn this feature off by using the command "-set colorspace:auto-grayscale=false". However, this option is not available in Wand latest version, is it a way I can turn off this feature by using Wand?
In addition, the command "-type truecolor" can also prevent Imagemagick convert the image to be grayscale. I try to set the image type to be "truecolor" by using "img.type = 'truecolor'" but the image is still converted to be grayscale, which is different behavior than the ImageMagick. Just want to know that is there something I did wrong or is there a way I can use to prevent black and white image to be converted into grayscale by using Wand?

In case anyone has the same issue.
You can use turn off auto-grayscale in wand.
with Image(filename='input.jpg') as img:
img.metadata['colorspace:auto-grayscale'] = 'false'

Related

Why ImageMagick changes image brightness when I simply want to convert between JPG and PNG?

I wanted to batch-convert some JPG images to PNG, so I used the following ImageMagick command:
convert before.jpg after.png
However, things didn't go as smooth as I planned. See two images below - first is before.jpg, second is after.png:
You can see that the second one is quite darker than the original.
I'm using ImageMagick 6.9.9-19.
Opening JPEG image in GIMP and exporting it as PNG gives expected result - output image is identical to original.
What am I doing wrong?
Edit: re-saving after.png with GIMP also makes the image identical to original.
Edit: even after I saved after.png with GIMP, re-converting with ImageMagick breaks colors again (convert after-gimp.png after-gimp-and-im.png).
Edit: converting to sRGB or CMYK TIFF, or even again to JPG, does not give this problem. However, I still need PNG.
The two images you posted are identical according to IM 6.9.9.20 Q16 Mac OSX compare -metric rmse GBooF.jpg geDxn.png null: Which produces: 0 (0). It is possible your viewers may display jpg and png differently, since neither have an sRGB profile. Though, png is usually assumed to be sRGB.
Also my viewer shows both of your images as the same --- no difference, in your post on Mac Safari and using Mac Preview.
Try adding an sRGB profile to your jpg. Then convert.
convert GBooF.jpg -profile path2/sRGB.icc GBooF2.jpg
convert GBooF2.jpg GBooF2.png
See if those view the same.

ImageMagick 6.7.7 conversion from RGB PDF to CMYK PDF looks dark

I am using ImageMagick 6.7.7 on Ubuntu 14.04.2.
I am converting an RGB PDF to CMYK PDF and it looks dark. But it is working fine with ImageMagick 6.6.6.
I am using below command:
convert tp_rgb.pdf -verbose -density 300 -colorspace CMYK tp_cmyk.pdf
How can we fix that? Can any help me with this?
At version 6.7.6, ImageMagick started treating grayscale images without colorspace information as "linear" instead of "sRGB" by default, with the result that they looked darker. Later, the default was switched back to "sRGB" and a few related problems were fixed. Upgrading to version 6.8.9 or later will restore the original, expected behavior, where all images are handled as "sRGB" by default.

How to get a gold foil look using ImageMagick

My requirement is to convert a image with a transparent background to look like gold foil (the way it’s printed on leather etc.)
I've been using ImageMagick and am getting excellent results with certain kind of PNGs but not with others.
The Image Magick command I am using is:
composite foil.png tmp.png logog.png outputg.png
foil.png is just a gold foil image
tmp.png is a plain/empty transparent background png
logog.png is the logo with transparent background
outputg.png is the output (this is what I need)
However, this kind of result does not occur in most other images with transparent backgrounds.
Ex.
logom.png gives outputm.png which is all gold
logos.png gives outputs.png which is all gold and all wrong
Download all files as zip from here from here http://sdrv.ms/1h7QW4A or view from http://s.imgur.com/a/ExLRE
I checked the encodings of these all PNGs and they are all the same. What is wrong with logom and logos that the outputs are not as they should turn out to be?
If I am approaching the solution from the wrong direction, please suggest alternatives.

iOS - Save UIImage as a greyscale JPEG

In my app, I convert and process images.
from colour to greyscale, then doing operations such as histogram-equalisation, filtering, etc.
that part works fine.
my UIImage display correctly, I also save them to jpeg files and it works.
The only problem is that, although my images are now greyscales, they are still saved as RGB jpegs. that is the red, green and blue value for each pixel are the same but it still waste space to keep the duplicated value, making the file size higher than it could be.
So when i open the image file in photoshop, it is black & white but when I check "Photoshop > Image > Mode", it still says "RGB" instead of "Greyscale".
Anyone know how to tell iOS that the UIImageJPEGRepresentation call should create data with one channel per pixel instead of 4?
Thanks in advance.
You should do an explicit conversion of your image using CGColorSpaceCreateDeviceGray() as color space which is 8 bits per component, 1 channel.

png to gif with transparency

I have a png image with some transparency. I would like to transform it to a gif image. I have tried imagemagik using convert myimage.png myimage.gif but transparency is not respected.
Any solution using linux commands? thanks
What you are doing should work out of box.
However, there's an important limitation of GIF as a format (not related to imagemagick). It does not support semi-transparency (alpha channel). Transparency in GIF is on/off (boolean).
Docs claim that the default behavior is to make pixels with (alpha<50%) fully transparent.
Depending on your image, you may achieve satisfactory results though. For example, by tweaking the threshold (code from ImageMagick docs):
convert a.png -channel A -threshold 15% a_no_shadow.gif
See more info on available options at:
http://www.imagemagick.org/Usage/formats/#gif

Resources