find opacity of pixels alpha layer
-
- Posts: 8
- Joined: 2017-03-16T05:00:27-07:00
- Authentication code: 1151
find opacity of pixels alpha layer
Hi everybody.
I've been trying to work this out for days.
I have an image and with the command line i want to find and delete all pixels that are below a given opacity level..
I.e. delete all pixels below 30% opacity.
How can this be achieved please as i cannot work this one out.
Regards and thanks
Matt
I've been trying to work this out for days.
I have an image and with the command line i want to find and delete all pixels that are below a given opacity level..
I.e. delete all pixels below 30% opacity.
How can this be achieved please as i cannot work this one out.
Regards and thanks
Matt
Re: find opacity of pixels alpha layer
Can you clarify what you mean by deleting the pixel? What should happen with it? Should it become transparent?
-
- Posts: 8
- Joined: 2017-03-16T05:00:27-07:00
- Authentication code: 1151
Re: find opacity of pixels alpha layer
thanks for the reply.
Yes, the pixel should be transparent.
Matt
Yes, the pixel should be transparent.
Matt
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: find opacity of pixels alpha layer
"-channel A -black-threshold 30% +channel" should do it.
snibgo's IM pages: im.snibgo.com
-
- Posts: 8
- Joined: 2017-03-16T05:00:27-07:00
- Authentication code: 1151
Re: find opacity of pixels alpha layer
thankyou...
"convert in.png -channel A -black-threshold 30% +channel out.png"
that command does something but it does no make the pixels transparent and instead just shows the original image that was faded.
i have a faded image and what i want to be able to do is make 100% transparent pixels that are say only 30% opaque or less.
Hope you can help out
Matt
"convert in.png -channel A -black-threshold 30% +channel out.png"
that command does something but it does no make the pixels transparent and instead just shows the original image that was faded.
i have a faded image and what i want to be able to do is make 100% transparent pixels that are say only 30% opaque or less.
Hope you can help out
Matt
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: find opacity of pixels alpha layer
What version of IM are you using? In some versions, IM was confused about alpha (because it used to store transparency, not opacity) so thresholds worked the wrong way round. For those cases, we can "-alpha extract", and "-black-threshold" that, then CopyOpacity the alpha channel back.
What shell do you use? If Windows BAT, the % needs doubling.
Can you show an example input? You can upload to somewhere like dropbox.com and paste the URL here.
What shell do you use? If Windows BAT, the % needs doubling.
Can you show an example input? You can upload to somewhere like dropbox.com and paste the URL here.
snibgo's IM pages: im.snibgo.com
-
- Posts: 8
- Joined: 2017-03-16T05:00:27-07:00
- Authentication code: 1151
Re: find opacity of pixels alpha layer
Thanks a lot.
To answer your questions.
Im using the command line on ubuntu.
Here is the image. https://www.dropbox.com/s/7efapn3t3vp5t ... e.png?dl=0
Basically the goal is 2 steps.
Step 1 make transparent the pixels that are 30% transparent or less.
Step 2 put a color for example red under every pixel (not the fully transparent ones).
The end result is an image with no semi transparent pixels at all and those that were semi transparent now have a red background colour.
Appreciate your help
Matt
To answer your questions.
Im using the command line on ubuntu.
Here is the image. https://www.dropbox.com/s/7efapn3t3vp5t ... e.png?dl=0
Basically the goal is 2 steps.
Step 1 make transparent the pixels that are 30% transparent or less.
Step 2 put a color for example red under every pixel (not the fully transparent ones).
The end result is an image with no semi transparent pixels at all and those that were semi transparent now have a red background colour.
Appreciate your help
Matt
- GeeMack
- Posts: 718
- Joined: 2015-12-01T22:09:46-07:00
- Authentication code: 1151
- Location: Central Illinois, USA
Re: find opacity of pixels alpha layer
Using IM 6.9.7 on Windows 10 64 I can get that result by running this command...bossrunner1 wrote: ↑2017-03-16T07:39:41-07:00i have a faded image and what i want to be able to do is make 100% transparent pixels that are say only 30% opaque or less.
Code: Select all
convert input.png -channel A -fx "p*(p>0.3?1:0)" result.png
-
- Posts: 8
- Joined: 2017-03-16T05:00:27-07:00
- Authentication code: 1151
Re: find opacity of pixels alpha layer
Thank worked fantastically and i appreciate you explaining how you did it... I understand for next time.
How would i put the red under the semi transparent part please?
How would i put the red under the semi transparent part please?
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: find opacity of pixels alpha layer
GeeMack got there before I did. GeeMack's solution will work, but "-fx" is slow. I find it too slow to be useful on large images.
The fx might be faster written as:
... so there is no multiplication.
You didn't say what version of IM you use. I assume v6. If v7, change "convert" to "magick".
The following turns all alpha values that are below 30% to zero. Thus, pixels that are mostly transparent become entirely transparent. This is Step (1) only.
Windows BAT syntax. For bash, escape each parentheses to \( and \), and change line-endings from ^ to \ , and change each doubled %% to a single % .
The following does your steps (1) and (2) together. It works by making a clone, and flattening it entirely against red. Then, as before, it applies a threshold to the alpha.
I assume you don't want to write the output of step (1) to a file. If you do, you could run both commands, or a single slightly more complex command.
The fx might be faster written as:
Code: Select all
-fx "p>0.3:p:0"
You didn't say what version of IM you use. I assume v6. If v7, change "convert" to "magick".
The following turns all alpha values that are below 30% to zero. Thus, pixels that are mostly transparent become entirely transparent. This is Step (1) only.
Windows BAT syntax. For bash, escape each parentheses to \( and \), and change line-endings from ^ to \ , and change each doubled %% to a single % .
Code: Select all
convert ^
test-image.png ^
( +clone -alpha extract -black-threshold 30%% ) ^
-compose CopyOpacity -composite ^
ti_30.png
Code: Select all
convert ^
test-image.png ^
( -clone 0 -background Red -layers flatten ) ^
( -clone 0 -alpha extract -black-threshold 30%% ) ^
-delete 0 ^
-compose CopyOpacity -composite ^
ti_30_r.png
snibgo's IM pages: im.snibgo.com
-
- Posts: 8
- Joined: 2017-03-16T05:00:27-07:00
- Authentication code: 1151
Re: find opacity of pixels alpha layer
Thanks to both of you... Fantastic work!!
I tried this and am on IM6.x and it works 99% as needed.
The red shows up but is semi transparent. What i need is the red 100% full pixel color not transparent with the original semi transparent pixel on top of it.
Hope this makes sense.
I tried this and am on IM6.x and it works 99% as needed.
The red shows up but is semi transparent. What i need is the red 100% full pixel color not transparent with the original semi transparent pixel on top of it.
Hope this makes sense.
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: find opacity of pixels alpha layer
Oops, sorry. In my second command, change "-black-threshold" to "-threshold".
snibgo's IM pages: im.snibgo.com
- GeeMack
- Posts: 718
- Joined: 2015-12-01T22:09:46-07:00
- Authentication code: 1151
- Location: Central Illinois, USA
Re: find opacity of pixels alpha layer
Adding to my example above and including the ideas from snibgo's examples, you might try something like this...bossrunner1 wrote: ↑2017-03-16T09:12:39-07:00The red shows up but is semi transparent. What i need is the red 100% full pixel color not transparent with the original semi transparent pixel on top of it.
Code: Select all
convert input.png -channel A -fx "p>0.3?p:0" \
\( -clone 0 -fill red -colorize 100 -clone 0 -compose copyopacity -composite \) \
+swap -compose over -composite result2.png
-
- Posts: 8
- Joined: 2017-03-16T05:00:27-07:00
- Authentication code: 1151
Re: find opacity of pixels alpha layer
Thanks geemack.
This doesn't work here - red is still transparent.
I have IM 6.697
Thankyou
This doesn't work here - red is still transparent.
I have IM 6.697
Thankyou
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: find opacity of pixels alpha layer
try snibgo's modification written in unix assnibgo wrote:Oops, sorry. In my second command, change "-black-threshold" to "-threshold".
Code: Select all
convert \
test-image.png \
\( -clone 0 -background Red -layers flatten \) \
\( -clone 0 -alpha extract -threshold 30% \) \
-delete 0 \
-compose CopyOpacity -composite \
ti_30_r.png
Code: Select all
convert \
test-image.png \
\( -clone 0 -alpha off -fill red -colorize 100 \) \
\( -clone 0 -alpha extract -threshold 30% \) \
-delete 0 \
-compose CopyOpacity -composite \
ti_30_r.png
Perhaps an example of your input and desired output results would help.