convert pixel alpha channel when alpha > 90% using imagemagick - 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.

Related

Magick equivalent of GIMP Hue-Chroma transformation

Using Gimp, given an input image, I can improve its contrast using Colors > Hue Chroma... by setting Chroma=50 (in a scale between -100 and 100) and leaving Hue=0 and Lightness=0. So it appears I'm doing an HCL transformation.
Is there an equivalent command for Magick?
The following image shows the GIMP effect:
Image
Updated Answer
Not sure about this at all. I think you can get pretty close with -modulate if you go into an LCH colourspace, but I have no idea if it will work consistently. I got:
magick cXDv3.jpg -define modulate:colorspace=LCH -modulate 100,150 result.jpg
If that doesn't work, or is not to your liking, read on...
Generic Method for any GIMP filters
The method below should allow you to replicate any GIMP filter with ImageMagick - as long as it is a pure "point process", I mean one where each pixel's output value is purely derived from its input value and not an "area process" where surrounding pixels contribute - such as blurring or median filtering, for example.
It's called a HALD-CLUT. You would create a HALD-CLUT something like this:
magick hald:16 clut.png
Then take that file (clut.png) into GIMP and apply your GIMP processing on it and save the result as GIMP-H0-C50-L0.png so we know how GIMP affects each colour. You do that just once.
Then you go back to ImageMagick and apply that CLUT to your image:
magick input.png GIMP-H0-C50-L0.png -hald-clut result.png
That gives me this:
and I think you'll agree the left side looks pretty similar to the right side of your input image.
Original Answer
I don't know what that command does in GIMP, but you can convert to HCL colourspace in ImageMagick and select the Chroma channel for modification like this:
magick INPUT.PNG -colorspace HCL -channel G ...
You then want to do something ? to affect the Chroma channel, so try -auto-level for now, and then return to sRGB colourspace and save:
magick INPUT.PNG -colorspace HCL -channel G -auto-level +channel -colorspace sRGB RESULT.PNG
Then you need to provide more clues or experiment more with what that command does in GIMP - or provide examples.

Preserving PNG transparency during a simple transformation in imagemagick

Task: i have an input png file (many actually, but i'll just loop the solution). It is 16x16 PNG, 32bit with partial transparency along edges.
It so happens that toolbar of a certain stupid platform requires 17x17 files. My problem is that imagemagick kills transparency when doing simple transformations.
So:
Sanity check:
convert add.png PNG32:add_COPIED.png
creates another 16x16#32bpp file. So far so good.
Transformation (gravity is fine):
convert add.png -extent 17x17 PNG32:add_17.png
creates a file with solid white background. That's not good.
What doesn't work:
I tried a serious number of combinations of transparent, transparent-color, background, alpha and flatten. Got nowhere.
What does work:
convert address_book.png -alpha Extract address_book_MASK.png
convert address_book.png -extent 17x17 PNG32:address_book_17.png
convert address_book_MASK.png -background black -extent 17x17 address_book_MASK17.png
composite -compose CopyOpacity address_book_MASK17.png address_book_17.png PNG32:address_book_FIN.png
While i have a working set of commands and I can get through the day, I honestly believe that this is the wrong way to do things - four commands that create 3 intermediate files that i need to delete later. Surely it can be done in a better way?
Set the background colour before changing the extent:
convert input.png -background none -extent WxH result.png

How to treshold image from greyscale screen by webcome

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.

Apply transparency with convert command

I have this two pictures http://s29.postimg.org/6j5m4jyx3/frame_0.png and http://s14.postimg.org/zdfn4f84x/frame_2.png and I need to mix both into a new picture with first at back and second at front with opacity at 70%.
To do it, I have this commands:
convert frame-2.png -background transparent -alpha set -channel A -evaluate set 70% frame-1.png
composite -background transparent -gravity center frame-1.png frame-0.png frame-1.png
Result is like I want but transparency to frame-2.png is applied with a strange way. I don't understand why transparent background also get a "black" opacity http://s27.postimg.org/bst4fmnhv/frame_1.png
Result should be http://s28.postimg.org/pb1ee1egt/frame_1.png
Ok, solution is using
-evaluate Divide 1.5
instead
-evaluate set 70%
And with this way, transparecy is applied perfect :)

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