quantize_area workings

Hello,

I was using quantize_area to eliminate small regions of constant value from a gray value image but it seems this is not what the command does, as it sometimes eliminates but other times extended the regions. Is that the expected result?

Below is an example. Note the region on the bottom right with an extended rod that did not exist before. I used quantize_area 2000.

I am adding colored versions of the images above to facilitate visualization. Colors before (top image) and after do not correspond.

Check out the area command first.

Thanks. I have checked. It reports area values but it does not wipe out those small ones with less than a given value.

quantize_area is an extension of area, so if the latter doesn’t solve your problem, the former might be the wrong command to use.

Please give us your input file so that we can make another suggestion.

The input file is above, on my first email, top image.

Upping the verbosity level I can see that quantize_area uses area to compute the area of connected components of given image,

[gmic]-1./quantize_area/*repeat/*local/ Compute area of connected components in image [1], with tolerance 0 and low connectivity.

but it assumes low connectivity which might be the culprit. When blobs are not touching each other quantize_area works as I expected, remove small blobs. Otherwise, it does what it does.

Oh, I thought there was more to your image. :blush:

You could try finding the gmic_stdlib.gmic on your system and editing changing area. 0,0 <. $1 to area. 0,1 <. $1 within the quantize_area command. Or overriding it with your own user.gmic copy, if you know how.

I will also ping @David_Tschumperle to see if he would consider adding the parameter.

Thanks for the suggestions. I think the processing is not complicated, just loop over the connected components, determine the area (number of pixels) of each, and whenever the area is below the quantized area value replace pixel values corresponding to that area by 0.

To make it more general, I would have area,connectivity,replace_value as parameters so one can decide besides area threshold which connectivity to use and which value to replace, instead of default 0. This is more like a threshold_area command.

I think this does the job for a threshold area of 2000

gmic image_blobs --area_fg 0,0 -gt. 2000 -mul

After coloring,

1 Like

Exactly, quantize_area deletes (as expectable) also holes (flat regions) with size less equal the threshold area, or better set them (I would call “deleting holes” filling them)! Maybe it would be a good idea to add an parameter to use only foreground objects, and possibly the connectivity as recommended by @afre. Still it is good to consider for foreground objects 4-connectivity and (automagically) for background objects 8-connectivity. Actually quantize_area mixes this a bit.

By the way my karo_segmentarea deletes only foreground objects with 4-connectivity but is by far not so nicely programmed!