Page 1 of 1

how to avoid loss of transparency due to overwriting color in png file

Posted: 2020-05-02T10:10:40-07:00
by manit
hi,
I am using
Version: ImageMagick 7.0.7-25 Q16 x86 2018-03-04 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2015 ImageMagick Studio LLC
License: http://www.imagemagick.org/script/license.php
Visual C++: 180040629
Features: Cipher DPC HDRI
Delegates (built-in): bzlib cairo flif freetype gslib heic jng jp2 jpeg lcms lqr openexr pangocairo png ps raw rsvg tiff webp xml zlib
on windows 10 home OS .

I have a png image containing a number written in black on white background.
My aim is to make a semi-transparent green circle around that number so that number can be read and is also covered in green color.
I am using following command

magick my-file.png -fill "#00FF0090" -draw "circle 140,30 140,55" my-file.png

I have observed that running the above command again causes the circle to get filled with a little more solid green so that black is less visible.
Actually, my script on each run will fill the same area with green color and I want that green to remain as it looked the first time.
See https://ibb.co/bdWQy0B
Here the first green filled number is ok for me.
But, the next number got almost completely overwritten by green which I do not want.
How can I overcome this ?

Re: how to avoid loss of transparency due to overwriting color in png file

Posted: 2020-05-02T10:31:24-07:00
by snibgo
That is like stamping a bingo card with semi-transparent ink. Each time you stamp the same place, you add more ink so less card will show through it.

The obvious solution is to not repeatedly stamp the same place.

Re: how to avoid loss of transparency due to overwriting color in png file

Posted: 2020-05-02T22:25:40-07:00
by manit
ok.
is it possible to detect whether that place already has green color ?

Re: how to avoid loss of transparency due to overwriting color in png file

Posted: 2020-05-02T23:55:29-07:00
by snibgo
An IM command could find the colour of a pixel, or the average of a number of pixels. You could use that in a script to determine whether that area had already been stamped.

Re: how to avoid loss of transparency due to overwriting color in png file

Posted: 2020-05-03T00:39:43-07:00
by manit
In my case , I want to count/detect green pixel in small circular area of whole image.
So , i have work on that patch .
I can mask the rest of image or extract that part and process it separately.

Re: how to avoid loss of transparency due to overwriting color in png file

Posted: 2020-05-03T10:56:00-07:00
by fmw42
If you threshold and make the green white and the rest black, then the average color times the area of the image will give you the count of white pixels (which are the green ones)

threshold your green image into black and white (not grayscale)

Code: Select all

convert black_white_image -format "%[fx:mean*w*h]" info:
is the count of white pixels.