Page 1 of 2
Request Enhancments Similar to -mode
Posted: 2011-03-16T17:24:45-07:00
by fmw42
I would like to request that -mode widthxheight be replicated to generate other statistical values, in particular -min, -max, -mean and -standard-deviation for a given rectangular widthxheight. I don't know if it is possible to put all the options under one name, such as -stats-filter. If so that would be OK and even better. But perhaps the syntax parser will not currently allow something like -stats-filter widthxheight+type where type is min, max, mean, or standard_deviation. This type of operation could even be expanded to such things as the average of k nearest in value (to the center value) and other such statistical operations.
I realize that -mean can be achieve by -blur radiusx65000 and -min and -max can be achieved via -morphology open/close square:radius, but the latter two are very slow and also I am not really sure how to convert the square:radius to the actual window size. Perhaps it is just radius=half-size. Clarification would be nice from Anthony. None however allow a rectangular area, only square area.
Discussion from others is requested and welcome before any action is taken. Are these worthwhile to others?
Thanks
Fred
Re: Request Enhancments Similar to -mode
Posted: 2011-03-16T19:47:19-07:00
by anthony
-min -max -mean are morphology operators erode, dilate, convolve.
Just specify the appropriate neighbourhood and channels
You can also use ErodeIntensity and DilateIntenasity
to select the color (whole pixel) based in the color intensity. (You can't get a -mean with intensity)
It was median the is very different (middle intensity of all pixels in neighbourhood).
Re: Request Enhancments Similar to -mode
Posted: 2011-03-16T20:42:28-07:00
by fmw42
anthony wrote:-min -max -mean are morphology operators erode, dilate, convolve.
Just specify the appropriate neighbourhood and channels
You can also use ErodeIntensity and DilateIntenasity
to select the color (whole pixel) based in the color intensity. (You can't get a -mean with intensity)
It was median the is very different (middle intensity of all pixels in neighbourhood).
Thanks, I accidentally used close and open rather than dilate and erode in my script. Hopefully that will fix it. But I want to be sure that in
-morphology erode/dilate square:radius
is radius just the size/2 (+1?) for a square. If I want the size to be 32, would I use radius of 16 or 17 or something else?
Re: Request Enhancments Similar to -mode
Posted: 2011-03-16T21:22:01-07:00
by anthony
Square:r is a square r*2+1 with the origin centered.
See
http://www.imagemagick.org/Usage/morphology/#square
Also look at rectangle!
Re: Request Enhancments Similar to -mode
Posted: 2011-03-16T21:30:19-07:00
by fmw42
Thanks, but still very slow compared to using -blur radiusx65000 to get mean. But there ought to be similar functions to get min, max, mean, standard-deviation, mode and other statistical operations on a rectangle that run faster than -morphology erode/dilate square:radius
Fred
Re: Request Enhancments Similar to -mode
Posted: 2011-03-16T21:33:43-07:00
by anthony
The -blur may be used some GPU processing for ultra fast processing.
Re: Request Enhancments Similar to -mode
Posted: 2011-03-16T21:36:57-07:00
by fmw42
anthony wrote:The -blur may be used some GPU processing for ultra fast processing.
But I need something similar to -blur for getting min and max in a region.
Re: Request Enhancments Similar to -mode
Posted: 2011-03-16T23:36:05-07:00
by anthony
Then your choices are either use morphology, or a dedicated (less neighbourhood controlled) MagickCore function for speed.
Aside. I want to make the change to Blur so that by default it understands transparency (no haloing).
To do this I would make -channel sync flag (turned on by default and means synchronize channel handling) perform what is current enabled using -channel RGBA
This will however mean that -channel RGBA (which turns off sync) will blur each channel separately and thus
could produce black transparency halos.
Basically it will bring the operator more in line with other operators, like -auto-level, -morphology, and the mathematical composition methods.
Re: Request Enhancments Similar to -mode
Posted: 2011-03-18T14:11:45-07:00
by fmw42
I withdraw my request. Seems for now, that -morphology and -blur achieves most of what I need.
Fred
Re: Request Enhancments Similar to -mode
Posted: 2011-03-18T14:15:37-07:00
by magick
Too late. -statistic {median, mode, minimum, maximum, nonpeak} has already been added to ImageMagick 6.6.8-6 Beta available by sometime tomorrow.
Re: Request Enhancments Similar to -mode
Posted: 2011-03-18T14:26:03-07:00
by fmw42
magick wrote:Too late. -statistic {median, mode, minimum, maximum, nonpeak} has already been added to ImageMagick 6.6.8-6 Beta available by sometime tomorrow.
Sorry you went to the trouble. I did not think you were going to implement anything until after discussions had finished. But since you have. Thanks.
But what about the dimensions argument? How does that work to specify the type of stats and the widthxheight? What is the syntax? What is non-peak? Also what about average (mean)? Or are you leaving that to -blur radiusx65000? And also standard-deviation? I guess these can come later.
Other variations can be found in the listings for my statsfilt script at
http://www.fmwconcepts.com/imagemagick/ ... /index.php, but I don't mean to suggest you necessarily implement any or all. But your implementation opens the door for other noise filtering variations such as in my script. Some of these require further arguments that may not fit into the current IM argument parsing.
Another good one, that I did not implement in my script is called kth nearest neighbor average. If you are so inclined, it averages the k (user supplied) pixels whose values are closest to the value of the center pixel along with the center pixels. However, the extra argument k, may not fit well with your current argument parsing!
Fred
Re: Request Enhancments Similar to -mode
Posted: 2011-03-18T14:30:01-07:00
by magick
Baby steps. The first release handles a neighborhood of widthxwidth.
Re: Request Enhancments Similar to -mode
Posted: 2011-03-18T14:37:38-07:00
by fmw42
magick wrote:Baby steps. The first release handles a neighborhood of widthxwidth.
Right. Just curious about the syntax.
Re: Request Enhancments Similar to -mode
Posted: 2011-03-18T14:59:59-07:00
by magick
Ok, we're supporting width x height afterall.
Re: Request Enhancments Similar to -mode
Posted: 2011-03-28T10:43:43-07:00
by fmw42
-statistic seems to be working correctly now in IM 6.6.8.10 Q16. Thanks.
This is not urgent, But at some point when you get time, could you possibly add standard-deviation. Here is one method that I have used. But do it any way you want.
For each channel:
1) Compute sum of graylevel and divide by N to get average
2) compute sum of graylevel^2 and divde by N to get average
3) Compute std = sqrt (variance) = sqrt( ave(g^2) - (ave(g))^2 )
see
http://en.wikipedia.org/wiki/Standard_deviation
http://en.wikipedia.org/wiki/Variance
Thanks
Fred