I have an image that want to adjust to look like a target image.
With the following adjustment I get closer to the target image, but I see a big difference in the red channel, specially in the shadows, my question is how can I adjust only this channel to get the result?
My command:
convert actual_srgb.jpg -contrast-stretch 4x0.8% bb_4x0.8.jpg
(BTW, I've applied sRGB profile to the initial image with the Adobe RGB profile)
source:
My result: (See the Red channel)
Target:
If you want to adjust just one channel in Imagemagick, then add -channel X to your command where X is R or G or B
convert actual_srgb.jpg -channel R -contrast-stretch 4x0.8% +channel bb_4x0.8.jpg
to adjust just the red channel for example.
Related
I want to use ImageMagick to change colour in shade.
I am able to manage the shade change using :
convert input.png -colorspace HCL -channel R -evaluate set 5% +channel -colorspace sRGB output.png
Using set XX% i am able to get different colours like, red, green, yellow, blue, pink, sky-blue, gray, etc.
The below command works for targeting blue colour :
convert input.png -colorspace HCL -channel R -separate +channel -level 48,52% output.png
But I am unable to target other colour explicitly.
For example, if I want to change green colour with some other colour, resulted image will effect green, yellow,red and sky-blue as well.
Is there a way to explicitly change a single colour in shade for :
yellow
sky-blue
pink
green
white
black
red
I tried changing all -channel : R,G,B,C,M,Y,K,A,O.
Using -separate option I can target RBG, but the problem with RGB is R effect red, yellow and pink, G effect green, sky-blue and yellow and B effect blue, pink and Sky-blue.
sample for output :
RGB image colour change
expected output : In the above output for "output-0" it effect red,yellow and pink. i want the command which will effect only red. similarly for other colours as well.
links I used : https://www.imagemagick.org/discourse-server/viewtopic.php?t=33361
I am using python to run this command. I am also open to use other libraries which will work with all the colours explicitly.
If your image is representative like I requested, it is as simple as this:
magick rgb.png -fill white -opaque red result.png
If you also want to affect hues "close to red", you can apply some fuzz:
magick rgb.png -fuzz 40% -fill white -opaque red result.png
Notice that also affects the edges of the red circle where it is a "feathered red".
If not, your ImageMagick code is essentially doing a "Hue rotation" and, as you have noticed, it affects the entire image. Read the Wikipedia page on HSV before continuing. Here is an HSI Hue wheel for reference:
The solution is to do your Hue rotation, but apply its effects via a mask that only selects the colours/areas you want affected. Remember that OpenCV halves the Hue from the range 0..360 to 0..180 so that it can store a Hue in a np.uint8.
So, if we load the same image as above and select only the greens (where Hue is near 120) we can rotate just those into blues by adding 60 (Hue=240):
#!/usr/local/bin/python3
import cv2 as cv
import numpy as np
# Load the image and convert to HSV colourspace
image = cv.imread("rgb.png")
# Convert to HSV and split channels
hsv=cv.cvtColor(image,cv.COLOR_BGR2HSV)
H,S,V = cv.split(hsv)
# Shift only greens (Hue near 120) around hue circle by 120 degrees to blues - remembering OpenCV halves all these values - see comment
H[(H>55)&(H<65)] += 60
# Recombine into single 3-channel image and convert back to RGB
result = cv.merge((H,S,V))
result = cv.cvtColor(result,cv.COLOR_HSV2BGR)
cv.imwrite("result.png",result)
If you want to change the blues (Hue=240) into yellows (Hue=60), just change this:
H[(H>55)&(H<65)] += 60
into this:
H[(H>115)&(H<125)] -= 90
If you want to broaden the range of greens affected, decrease the 55 in my code and/or increase the 65. If you want to move greens to a different hue, either increase or decrease the 60.
You can do all the stuff above with PIL/Pillow if you want to - you don't need to install the (massive) OpenCV.
Keywords: Image, image processing, Python, OpenCV, ImageMagick, Hue, HSL, HSV, hue rotation, colour replacement, selective colour, mask.
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 am trying to convert some custom image filters with ImageMagic command line from PhotoShop tutorials. I can manage to work out most of it, but when it comes to "Curves", I can't seem to find any information on how to translate the following using ImageMagic command line.
Image > Adjustments > Curves. Go into the green channel and put the output to 32 and then go to the blue channel and put the output to 110.
I am trying to adjust the colors in the $img_in in this example:
$img_in = "image.jpg";
$gradient = "convert -size $dim radial-gradient:#f7d9ad-#f0ce9b ";
$c = " $gradient -compose multiply -gravity center -composite ";
exec("convert $img_in $c $img_out");
Any help here would be appreciated.
If you mean you want to set the curves so that the maximum output value of the green channel is 42, you are effectively scaling the green channel by a factor of 42/255. So, if your original inage was, say, white, and your green channel curve looks like this, your image would be more red and blue (i.e. purplish) like this when you reduce the green to 42/255 of its full-scale value.
then you could achieve the same effect in ImageMagick using the fx operator like this:
convert -channel green input.jpg -fx "u*42/255" out.jpg
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.
I'm trying to chromakey some pictures. Here is an example of one:
Here is another one,
Now using image magic, I can generate a mat like this..
But I can never get the mat to be "full". My plan is to create a static mat for the turntable and the lightbank -- those won't have to be removed. But, I'd like to fix the problems I'm seeing with the grill, licenseplate, and window. I'd like the car to show up pitch-black. I'm using ImageMagick's convert to get this working,
convert 1.bmp -channel g -separate +channel -fuzz 45% -fill black -opaque black -fill white +opaque black greenscreensample_mask_1.gif
How can I improve this to fill in the bumper of the vehicle?
I would guess the shinny parts are slightly green and you could try reducing the fuzz value.
You can use the -fx operator and then work with specific channels. The following is by no means optimal, and also, it is very inefficient to execute:
convert ./in.jpg -background none -transparent white -channel Alpha -fx '1-((g-r)+(g-b)+(g-(r+b)/2))^2' -channel Green -fx '(r+b)/2' ./out.png;eog ./out.png
in order to obtain a key for the green channel you can subtract the
red from the green
blue from green
average of blue and red channels from the green channels
the very basic colour correction involves replacing fringed areas with the average of the blue and red channels, here however the entire image had its green channel replaced with the average of the blue and red channels. you should actually write an algorithm that seperates the fringe into a seperate channel, then you colour correct the entire image and mix it in with the original based on this "fringe" matt.
thankyou, best of luck