Is there a way to move all gray colors of a CMYK image (e.g. a CMYK .tiff) into the black (K) plate with ImageMagick?
(In Adobe Acrobat Pro, this functionality is labeled: "Promote grays to CMYK black")
Here's an image to experiment with:
You can view an example of this process on Wikipedia.
Also not a full answer as such, but hopefully useful towards producing one - by Kurt, myself or others. I looked at the Photoshop method of GCR and am adding the characteristic curves that Adobe seem to use for GCR. There are 5 levels, ranging from "None", through "Light", "Medium", "Heavy" and "Full".
I presume the "Light" curve is showing that no black ink is added into the mix till it would be over 50%, and the "Medium" shows the black would have to be only 25% before any gets added, and the "Heavy" shows that only 12-15% of black is needed before black ink gets added into the mixture.
I also add the following reference to assist any other answerers... see PDF here.
Taking into account that the provided example image is NOT a TIFF (as announced), and does NOT use a CMYK color space (as announced), but is a JPEG using sRGB, here is how you would convert it into a TIFF file using CMYK, where the black channel is used:
convert \
http://i.stack.imgur.com/HFnCz.jpg \
-colorspace cmy \
-colorspace cmyk \
cmyk.tiff
To separate out the different colors again and show them as grayscale images each, use these commands:
convert HFnCz.tiff -colorspace cmyk -channel c -separate channel_c.png
convert HFnCz.tiff -colorspace cmyk -channel m -separate channel_m.png
convert HFnCz.tiff -colorspace cmyk -channel y -separate channel_y.png
convert HFnCz.tiff -colorspace cmyk -channel k -negate -separate channel_k.png
I did output to PNG in order to keep the file size a bit smaller...
Here are the 4 color separations. Top left is C, top right is M, bottom left is Y, bottom right is K:
Update
I made a mistake in my original answer. The -negate command parameter should only be there for the blacK channel.
Related
When comparing two images, both of the images are the same, except that in one of the images the text is moved by a couple of pixels. Please take a look at the below URL. It is a GIF that shows the difference of both the similar images.
https://giphy.com/gifs/9x50JjoLSPZ7lKRebk
My team initially used compare command which doesn't address this issue. Need suggestions please?
You can remove all the text in Imagemagick and just compare the bars by thresholding the Saturation/Chroma channel and then doing the compare. The text is gray, so it has little if any saturation. The bars are cyan, so they are colored and have a medium to high saturation.
convert giphy.gif -colorspace HCL -channel g -separate +channel -threshold 5% +write tmp.gif miff:- | compare -metric rmse - null:
3164.96 (0.0482942)
So this is 4.8% different.
I save tmp.gif, which you do not need, only to show the result of the processing before the compare.
If your version of Imagemagick is too old and you do not have -colorspace HCL, then try HSL or HSB. C and S are similar and measure saturation/chroma.
I want to get the mean of a sequence of images by using Imagemagick. Therefore I use the following command:
convert *.png -evaluate-sequence mean MEAN.png
Each of my images does contain an alpha channel. What I want is: Combine all the images by ignoring the alpha channel.
When I combine the images, the alpha channel is considered in the "mean" method and my final image has transparency. That isn't what I want.
Result:
I tried to add the parameter -alpha off, but then Imagemagick converts the alpha channel to black.
convert *.png -alpha off -evaluate-sequence mean MEAN.png
Result:
Photoshop does it right. I load all images in a stack and create a smart object. When I use the "mean" method in Photoshop, the alpha channel is not considdered in the final result.
Result that I want with Imagemagick:
Does someone have an idea how to do that with Imagemagick?
What you need to do is to use the alpha channels as weighting images for each image. The total fraction of white values at each pixel from all the alpha channels would be the weight to use for the average. So something like this should do what you want or at least be close.
First, cd to your directory of images. Then run the following.
convert *.png -evaluate-sequence mean \
\( -clone 0 -alpha off \) \
\( -clone 0 -alpha extract \) \
-delete 0 +swap -compose divide -composite result.png
This will work if there is some image texture at each pixel coming from al least one image. That is at a given pixel all images are not totally black (transparent).
compare -metric rmse result.png mean_photoshop.png null:
125.167 (0.00190993)
So this shows that there is about 0.2% difference between my result and what you got from photoshop
Maybe this way of working will help you get there - or at least explain the problem:
convert xc:"rgba(255,0,0,1)" xc:"rgba(0,0,0,1)" xc:"rgba(0,0,0,0)" -depth 8 -evaluate-sequence mean txt:
Output
# ImageMagick pixel enumeration: 1,1,65535,srgba
0,0: (21845,0,0,43690) #550000AA srgba(85,0,0,0.666667)
Using IM 6.8.9.4 Q16 or IM 7.0.5.5 Q16 Mac OSX Sierra, this seems to work fine for me:
Make transparent image
convert logo: -transparent white logot.png
Get mean
convert logot.png logot.png logot.png -alpha off -evaluate-sequence mean result.png
magick logot.png logot.png logot.png -alpha off -evaluate-sequence mean result.png
This also seems to work:
convert logot.png logot.png logot.png -channel rgb -evaluate-sequence mean -alpha off result.png
So perhaps you need to upgrade your ImageMagick (and/or libpng?)
Can you post a zip file of some of your input images, so we can test with your images?
One problem that I see is that the PNG images that you provided have black under the transparent areas and not image texture. So when you disable alpha as in my commands above, you see black and the black gets averaged into the final result. Did you use these same PNG images in Photoshop or did you have Photoshop PSD images or some other images that you used and then exported to PNG, which may have put black under the transparent areas. Have you tried using the same PNG images in Photoshop to do the average?
In fact, you have 8-bit color (palette) images, which have one color (black) assigned to be the transparent color.
How how would i generate an image of certain resolution containing black and white noise. I want to generate a number of images with each images noise being different. Prefer if done in console of either linux or windows but coding is ok if really have to.
Cheers
Like this with ImageMagick which is installed on most Linux distros and is available for macOS and Windows:
convert -size 512x512 xc:gray +noise random -colorspace gray noise.jpg
Replace convert with magick if using v7+ of ImageMagick.
If you mean pure black and white without shades of grey, and maybe would like a different size and a PNG format, use:
convert -size 600x400 xc:gray +noise random -colorspace gray -threshold 50% noise.png
If you want a different distribution of noise (gaussian, poisson, binomial) or to attenuate the noise, have a look at my other answer here.
I have image like this from my windstation
I have tried get thoose lines recognized, but lost becuase all filters not recognize lines.
Any ideas what i have use to get it black&white with at least some needed lines?
Typical detection result is something like this:
I need detect edges of digit, which seams not recognized with almost any settings.
This doesn't provide you with a complete guide as to how to solve your image processing question with opencv but it contains some hints and observations that may help you get there. My weapon of choice is ImageMagick, which is installed on most Linux distros and is available for OS X and Windows.
Firstly, I note you have date and time across the top and you haven't cropped correctly at the lower right hand side - these extraneous pixels will affect contrast stretches, so I crop them off.
Secondly, I separate your image in 3 channels - R, G and B and look at them all. The R and B channels are very noisy, so I would probably go with the Green channel. Alternatively, the Lightness channel is pretty reasonable if you go to HSL mode and discard the Hue and Saturation.
convert display.jpg -separate channel.jpg
Red
Green
Blue
Now make a histogram to look at the tonal distribution:
convert display.jpg -crop 500x300+0+80 -colorspace hsl -separate -delete 0,1 -format %c histogram:png:ahistogram.png
Now I can see all your data are down the dark, left-hand end of the histogram, so I do a contrast stretch and a median filter to remove the noise
convert display.jpg -crop 500x300+0+80 -colorspace hsl -separate -delete 0,1 -median 9x9 -normalize -level 0%,40% z.jpg
And a final threshold to get black and white...
convert display.jpg -crop 500x300+0+80 -colorspace hsl -separate -delete 0,1 -median 9x9 -normalize -level 0%,40% -threshold 60% z.jpg
Of course, you can diddle around with the numbers and levels, but there may be a couple of ideas in there that you can develop... in OpenCV or ImageMagick.
I have an image in .jpg format with white background color. I want to remove the white background color to transparent in Imagemagick. I tried many ways but still the white background can not be removed. Can some one help me to solve this.
You cannot have transparent background colors in your JPEGs. The JPEG file format doesn't support transparency.
If you need transparent background, you need to convert the JPEG to
either PNG (high quality, filesize possibly larger than JPEG)
or GIF (in case you can tolerate low quality and a range of maximally 255 colors).
Example command:
convert your.jpg -transparent white your.png
First, you need to convert the image format from .jpg to .png format, because JPEG does not support transparency. Then use this command:
convert image1.png -fuzz 20% -transparent white result.png
The -fuzz option allows the specified percentage deviation from the pure white colour to be converted to transparent as well. This is useful, for example, when your image contains noise or subtle gradients.
I just found a very neat thing!
magicwand 1,1 -t 20 -f image -r outside -m overlay -o 0 image.jpg imgOutput.png
It is a Fred Weinhaus bash script that can be downloaded from here (for non commercial use only). Also there has about 250 scripts!! and this one is amazing! it did exactly the trick, to remove all background while keeping the inner image dots untouched!
At his page, there are several images as examples so you pick what you need to put on the command line!
The initial position 1,1 is a general guesser saying all the contour is background.
Pay attention that the output must be ".png"
This is my solution without magicwand (replace magick by convert for im < 7.0):
magick img.png -fuzz 20% -fill none -draw "alpha 1x1 floodfill" result.png
Get the background automatically and remove it :
bg=$(convert input.png -format "%[pixel:p{0,0}]" info:)
convert input.png -fuzz 20% -transparent "$bg" output.png