Remove some characters on image

Hi everyone,

I have an ultrasound image. I want to remove some characters (green color) from the image and change to a gray image. Is it possible?

Thank you,

Hello Nhuchan -

Yes, see the IJ Macro, below. (There are lots of ways to do this.
I chose a pure-IJM approach.)

First, some observations:

The image you posted is an RGB image (three 8-bit channels).
I’ve chosen to produce a pure 8-bit grayscale image (but you
could convert it back to RGB if you cared).

Your sample image has green tick marks at the bottom (in
addition to the green characters). We’ll get rid of those, too.

Two issues make the processing a little more delicate: First,
your green characters are not an exactly uniform shade of
green. Second, and a bit more of a nuisance, there are
“artifacts” around your green characters where the gray image
is not exactly gray, but has some residual color.

Anyway, the processing will run as follows: We separate
your RGB image into its “Hue,” “Saturation,” and “Brightness”
components. The “Brightness” image is already an 8-bit
grayscale image, so it washes out the residual color artifacts.

The “Saturation” image shows us where the green characters
(and tick marks) are. We use it to create an Roi that we apply
to the “Brightness” image and fill the Roi with a hard-wired
background gray value. (You could get fancier and average
over some section of the image to automatically determine a
suitable background gray value.) The filled Roi is then “flattened”
to overwrite the characters with the background gray value in
the image itself.

Here is the IJ Macro:

print (IJ.getFullVersion);
open ("green_characters.png");   // your sample image
run ("HSB Stack");
run ("Stack to Images");
selectWindow ("Hue");
saveAs ("png", "green_characters_hue");   // to see artifacts
close ("green_characters_hue.png");
selectWindow ("Saturation");
setOption("BlackBackground", true);   // persistent option
run("Convert to Mask");   // saturated characters are in mask
run ("Create Selection");
roiManager ("Add");
close ("Saturation");
selectWindow ("Brightness");
roiManager ("select", roiManager ("count") - 1);   // apply mask-roi to Brightness image
roiManager ("deselect");
Roi.setFillColor (40, 40, 40);   // hard wire 40 as background gray
run ("Fill");   // set mask-roi pixels to background gray
run ("Flatten");   // make grayed-out mask-roi part of image
close ("Brightness");
saveAs ("png", "characters_removed");

The output for my Fiji / ImageJ version:


And the processed image with the characters removed:



Lastly, to illustrate the artifacts I mentioned above, here is
the “Hue” channel of your original image:



Thanks, mm

1 Like

Hey @Nhuchan and @mountain_man ,

great discussion over here. I just want to raise the flag for good scientific practice. Such a workflow is an edge case of things that should not be done or be done very carefully. At least the procedure must be correctly documented. I’d recommend to not process the resulting images as if they were original images. Otherwise, later in the review process of your scientific work, reviewers might find artifacts in the manipulated region and ask uncomfortable questions :wink:



Hi @mountain_man, @haesleinhuepf
Thanks for your nice solution and suggestion.
Nice tool.
Thank you all for your time.-))