Hello all,
I am fairly new to using the ImageMagick software. I am looking to perform a rather simple task, but after digging through the forum for a couple of hours and trying out several options I have not succeeded in reaching my goal.
My goal:
- I have an image with several colors
- I want to select all pixels of a specific color in the original image (result may be black and white)
- Must be possible to perform this in batch mode
This thread has given me some pointers, but my brain does not cooperate with me understanding it
viewtopic.php?f=10&t=8711
I think the approach should be to create a mask which highlights only the pixels of the specific color (lets say 'red').
I have tried to indicate that 'red' should be the transparency color and then create a mask from that using the matte channel:
From the samples:
convert drawn.png -channel matte -separate +matte matte.png
But my attempts were far from successful.
Hmm, update...! Found this post:
viewtopic.php?p=21394#p21394
convert colorwheel.jpg -matte \
\( +clone -fuzz 30% -transparent blue \) \
-compose DstOut -composite all_blue_colors.png
Which suggests to make all pixels not near the same color of 'red' (in my example) transparent. Although this works, it uses the -fuzz attribute, but I only want to select ONE color. (changing the -fuzz to 1 does not seem to work, 2% does seem to work, but I think too many colors will fall within the range).
My question is:
- Am i on the right track?
- Is there an easier way to do this?
- Or... How do I do this!!!
I am a bit lost at this point... Any help greatly appreciated!
Removing all but one color
Re: Removing all but one color
Best way to solve your problem is by formulating your problem... I seem to have been able to do it after all:
convert step0.png -matte ( +clone -fuzz 1 -transparent #8787b4 ) -compose DstOut -composite step1.png
The remaining steps should not be too difficult (making the remaining pixels black instead of the original color).
Thanks for your help
convert step0.png -matte ( +clone -fuzz 1 -transparent #8787b4 ) -compose DstOut -composite step1.png
The remaining steps should not be too difficult (making the remaining pixels black instead of the original color).
Thanks for your help
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: Removing all but one color
Replace the non-transparent pixels with black...
replace transparency with white
I added the +compose to turn off the previous -compose switch.
Code: Select all
-fill black -colorize 100%
Code: Select all
-background white +compose -flatten
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/