ImageMagick equivalent to PhotoShop Curves - 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

Related

Ignore the colour white in the imagemagick convert colors histogram output

I would like to ignore/filter white and those that are close to white when using this type of command
convert $file -colors 10 -format "%c" histogram:info:
I have some images that are predominantly white in their content and i'd like to focus on the other colours.
I thought i could use something like -fuzz 20% -fill "#0000ff" -opaque white to change all white and white'ish into a simple blue which i could then grep out in the histogram output but no luck.
Can anyone point me in the correct direction or offer an example please ?
Let's say for example i have a photo that contains a very overexposed sky i.e lot's of white. I'd like the histogram output to ignore that part of the photo and instead output the other top 10 colours that are in the photo.
Thanks
fLo

Apply gradient mask on image that already has transparency with ImageMagick?

I've got a PNG image with transparency:
original.png
Now I want to use ImageMagick to apply a diagonal gradient to its alpha channel. I mean so that its opacity remains in the top left corner, and gradually fades out to completely transparent in the bottom right corner. Like this:
result.png
So basically I want to generate a gradient, and use that as a mask for the image. But the image already has an alpha channel (transparency) of its own. Here's a visualisation of what I'm trying:
(original and result here displayed on checkerboard for visiblity, but I mean actual transparency)
I think I understand how to generate a diagonal gradient (the barycentric gradient command is very useful for this). But this creates a gradient in the color channels i.e. a colored or grayscale gradient. Whereas I want to apply the gradient on the alpha channel.
From the IM manual I understand the -compose CopyOpacity operator could be used for this. However this seems to copy the alpha from the mask on to my image. I need to "apply" this gradient color on my existing alpha channel, so basically I need my image's alpha channel to be multiplied by the grayscale color from the gradient image.
What would be the correct IM command line to perform the operation displayed above?
Here is one way you could do it:
convert tree.png -write MPR:orig -alpha extract \
\( +clone -colorspace gray -fx "1-j/h" \) \
-compose multiply -composite -write alpha.png \
MPR:orig +swap -compose copyopacity -composite result.png
The -write alpha.png can be omitted - it just shows the alpha layer for debugging and illustration purposes.
The MPR is just a temporary copy of the original image that I hold in memory while I am dinking around with the alpha channel and which I bring back near the end. The gradient in the alpha channel is generated by the -fx and I made the colorspace gray first so it only has to run once, instead of three times.
If you knew the dimensions of the tree image up front, you could replace the part in parentheses with:
-size WxH gradient:black-white
but I don't know the dimensions up front and I don't want a second convert command to get them, so I basically clone the original image's alpha channel to get a canvas the right size and fill it in with -fx.

convert pixel alpha channel when alpha > 90% using imagemagick

I need to convert existing png 2 areas files : one area is transparent and the other is red or blue opaque (one sample here : http://urlz.fr/31t2).
I want to keep the first area tranparent and to convert opaque area to 30 or 50% of opacity.
I'm desperatly looking for a solution using Imagemagick, as a radio engineer i'm not comfortable with the IM ressources ...
I'm only able to convert the whole image to X% of opacity (convert input.png -alpha set -channel A -evaluate set 50% output.png
)but that's not what i am looking for !
Thanks for your quick and accurate answer to my not so accurate question!
That looks like something i have just found (excepted the use of "u" as a variable rather than a value) :
convert input -channel A -fx "(a>0.99)?0.3:0" output
For sure, your writing is more elegant !
Your question is quite hard to understand, but I think you want this:
convert image.png -channel A -fx "u>0.9?0.3:u" result.png
Wherever the alpha is more than 0.9, it will be set to 0.3, otherwise it will be untouched.

ImageMagick : remove white lines

I'm trying to remove white lines which cute in pieces an image.
I'm using :
convert input.png -fill white +opaque "#e6e6e6" -fill black -opaque "#e6e6e6" -median 2 -magnify result.png
to remove the background with the following output :
How could I remove those white lines using ImageMagick ?
Thanks
You could use the morphological operators that have been introduced into ImageMagick, specifically the dilation operator. It grows the white regions of the image, which is the opposite of what you want so we negate the image first, making blacks white, do the morphology then negate back to your original.
As the gaps are along a horizontal line, we want a vertical structuring element for the morphology, so we can use a vertical line one pixel wide and several pixels tall - I chose 9 pixels. So, all in all, your command looks like this:
convert in.jpg -negate -morphology dilate rectangle:1x9 -negate out.jpg
The result looks like this:

Creating a more effective matt for chromakey?

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

Resources