Page 1 of 2
remove red dot from top left corner of 32bit png images.
Posted: 2014-06-25T18:18:25-07:00
by serrotos
Hello. I needed to do batch resizing to 32 bit png images and all png images have 1 pixel red dot,which I intentionally painted to use as a mark,on top left corner of images(x 0 Y 0 coordinate.). After resizing,I need to replace it with transparent 1 pixel dot,but I can't.
1 pixel red dot's color value is #FF0000, so I try to remove it using convert-transparent #FF0000, but red dots have alpha value too, and it changes between 1 to 255, so it did not work.And I thought -fuzz would do the trick but it will change other part of drawings too, so I can't use it too.
Drawings are something like these. All drawings have 1 pixel red dot on top left corner of themselves.
What should I do? Please give me your advice.
Re: remove red dot from top left corner of 32bit png images.
Posted: 2014-06-25T18:51:49-07:00
by snibgo
Make the pixel at (0,0) into transparent black:
Code: Select all
convert 14io28i.png -fill rgba(0,0,0,0) -draw "color 0,0 point" out.png
Re: remove red dot from top left corner of 32bit png images.
Posted: 2014-06-25T19:30:19-07:00
by fmw42
After resizing,I need to replace it with transparent 1 pixel dot,but I can't.
You should replace before resizing. Otherwise, the red dot color will change due to mixing with neighboring colors (and alpha values). Snibgo's command is correct for replacing before resizing.
Code: Select all
convert 14io28i.png -fill rgba(0,0,0,0) -draw "color 0,0 point" -resize ... PNG32:out.png
However, you may want it to transparent white rather than transparent black, since your color under the alpha channel is white in that region.
Code: Select all
convert 14io28i.png -fill rgba(255,255,255,0) -draw "color 0,0 point" -resize ... PNG32:out.png
Re: remove red dot from top left corner of 32bit png images.
Posted: 2014-06-25T19:38:39-07:00
by snibgo
Thanks, Fred. Yes, I missed:
After resizing,I need to replace it with transparent 1 pixel dot,but I can't.
My method will only work
before resizing. Removing redness
after resizing would be difficult.
Re: remove red dot from top left corner of 32bit png images.
Posted: 2014-06-25T20:50:28-07:00
by serrotos
Thank you for your comments.
I don't need to worry about mixing, because I placed the red dot on the place where there are no colors around. And I need to have transparent dot.
I tried to batch all files of all sub folders, but this does not work.
it says I used -draw incorrectly.
Code: Select all
FOR /R %A IN (*.png) DO ( convert "%A" -fill rgba(0,0,0,0) -draw "color 0,0 point" png32:"%~npA.png")
I just want to replace 1 pixel red dot with 1 pixel transparent dot, and this script place 1 pixel transparent on top lef, x0 y0, right?
Re: remove red dot from top left corner of 32bit png images.
Posted: 2014-06-25T21:00:40-07:00
by serrotos
And I should have said that I need to do resizing before removing red dot, because I need to use After Effects to do render and resizing. AE's resizing is crisper than ImageMagick.
Re: remove red dot from top left corner of 32bit png images.
Posted: 2014-06-25T21:04:02-07:00
by fmw42
I don't need to worry about mixing, because I placed the red dot on the place where there are no colors around. And I need to have transparent dot.
That is not true if you resize first. The red pixel is surrounded by white pixels with transparency. If you resize, the red will mix with the white and the transparency of the white will mix with the opacity of the red pixel.
I do not use Windows, so you will need to wait for user snibgo to respond about any errors in your script commands. However, you can use mogrify to the processing on any given folder without having to script a loop.
Create a new directory (new). Assume all your original images (before resizing) are in a directory (old). Then cd to old. Then do
Code: Select all
mogrify -path path2/new -format png -fill rgba(0,0,0,0) -draw "color 0,0 point" *.png
This command will create new images in directory new with the same name as the ones in directory old, but they will have had the red pixel replaced with black transparency. I would suggest you use white transparency, e.g rgba(255,255,255,0) if all your images have white around the pixel at 0,0.
You can even add the resizing to the command after the -draw command, if you want.
Re: remove red dot from top left corner of 32bit png images.
Posted: 2014-06-25T21:41:42-07:00
by serrotos
OK. This works fine.
Code: Select all
FOR /R %A IN (*.png) DO ( convert "%A" -fill "rgba(255,255,255,0)" -draw "color 0,0 point" png32:"%~npA.png")
Seems I need to add quotation to -fill. Thank you very much. It saves tons of times.
I will use white transparent color. I never thought about color of transparent area. Will it cause any problem if I use black transparent instead?
That is not true if you resize first. The red pixel is surrounded by white pixels with transparency. If you resize, the red will mix with the white and the transparency of the white will mix with the opacity of the red pixel.
Really? I checked neighboring areas where I put red dot, but there is no colors. You can find some colors around red dot on my drawings I posted? I can't.
And I am a super noob and I couldn't make mogrify work, but thank you for your advice. I will use it next time.
Re: remove red dot from top left corner of 32bit png images.
Posted: 2014-06-25T22:56:04-07:00
by fmw42
Put quotes about the rgba color
Code: Select all
mogrify -path path2/new -format png -fill "rgba(0,0,0,0)" -draw "color 0,0 point" *.png
In windows, I think your path is likely something like
C:\....\new
The new directory must be created before you invoke mogrify. And you must have cd (changed directories) to the old directory before you invoke mogrify
see
http://www.imagemagick.org/Usage/basics/#mogrify
If you just resize, without replacing the red first, you may not see any other pixels with red after resizing without extracting the exact colors. Then you might see some pink pixels with partial transparency. But the red pixel will not be the same pure red, you started with.
You can use black transparent if you want, so long as you do not care what is under transparent pixels.
Re: remove red dot from top left corner of 32bit png images.
Posted: 2014-06-25T23:17:29-07:00
by serrotos
Thank you. I will check the page.
I don't care so much about the red color. I will delete it anyway. I need to have the red pixel to make it border area to trim image's useless transparent areas that After Effects makes when rendering. Red pixel also tells me x y coordination of images.It's hard to trim transparent areas using After Effects because of it's composition system. So I use imageMagick to trim. It's so useful.
And I have a question one more thing.Is it possible to do something like this?
ImageMagick checks what color is on x0 y0 position, and if it's RGB 255,0,0(ignoring alpha value)replace it with transparent color and if it's not, do nothing.
I have lots of files and folders and those folders have images that have other colors on x0 y0 position.
If imageMagick can do the trick it will be great.
Re: remove red dot from top left corner of 32bit png images.
Posted: 2014-06-26T06:57:45-07:00
by snibgo
You could do it in a single command with a mask, or as multiple commands, Windows BAT syntax:
Code: Select all
FOR /F "usebackq skip=1 tokens=6 delims=():, " %%C ^
IN (`convert 14io28i.png ^
-alpha off ^
-crop 1x1+0+0 ^
-depth 16 ^
txt:`) ^
DO set ONE_PIXEL=%%C
if "%ONE_PIXEL%"=="#FFFF00000000" (
convert 14io28i.png -fill "rgba(0,0,0,0)" -draw "color 0,0 point" out.png
)
EDIT: Doing this in a single command with a mask:
Code: Select all
convert ^
14io28i.png ^
( -clone 0 ^
-fill rgba(0,0,0,0) -draw "color 0,0 point" ^
) ^
( -clone 0 ^
-alpha off ^
-fill Black -colorize 100 ^
-fill White -opaque Red ^
) ^
-composite ^
out2.png
Re: remove red dot from top left corner of 32bit png images.
Posted: 2014-06-27T19:12:02-07:00
by serrotos
Sorry for my late reply.
It works fine when I use it with convert and I tried to use it with mogrify, but failed.
Code: Select all
FOR /F "usebackq skip=1 tokens=6 delims=():, " %C ^
IN (`mogrify *.png^
-alpha off ^
-crop 1x1+0+0 ^
-depth 16 ^
txt:`) ^
DO set ONE_PIXEL=%C
if "%ONE_PIXEL%"=="#FFFF00000000" (
mogrify -fill "rgba(0,0,0,0)" -draw "color 0,0 point" *.png
)
I changed it like this, and I am sure that if clause works fine, but I think
`mogrify *.png^ is wrong. What should I do?
And one more thing, I tried to use mogrify again and again, but It won't work on WIndows7 and I found out that my file path has non-English words. I changed file path to English and it works.
Is it possible to use mogrify without changing file path? If I need to change it's a disaster.
Re: remove red dot from top left corner of 32bit png images.
Posted: 2014-06-27T20:00:30-07:00
by snibgo
The syntax for mogrify is different to the syntax for convert.
But your code wouldn't make any sense. You would find the top-left pixel of all of the images, then use only one of them to decide whether to change the pixel of all of the images.
Re: remove red dot from top left corner of 32bit png images.
Posted: 2014-06-27T20:16:13-07:00
by serrotos
Thanx. So is this possible?
(check the top left corner of *.png and if it's red, replace it with transparent color,if it's not do nothing) to all images of all folders.
Re: remove red dot from top left corner of 32bit png images.
Posted: 2014-06-27T20:24:58-07:00
by snibgo
Put the whole thing inside a "for" loop.