Page 2 of 4

Re: halo minimization by local min/max smooth clamping

Posted: 2011-04-03T16:11:32-07:00
by NicolasRobidoux
Does lighten/darken only affect the luminance based on the luminance, or does it work channel by channel?

Re: halo minimization by local min/max smooth clamping

Posted: 2011-04-03T16:31:00-07:00
by fmw42
Image

infile="house3a.png"
inname=`convert $infile -format "%t" info:`
filt="triangle"
fact=150
convert $infile \
\( -clone 0 -filter lanczos -resize $fact% \) \
\( -clone 0 -statistic minimum 3x3 -filter $filt -resize $fact% \) \
\( -clone 0 -statistic maximum 3x3 -filter $filt -resize $fact% \) \
\( -clone 1 -clone 2 -compose lighten -composite \
-clone 3 -compose darken -composite \) \
-delete 0-3 ${inname}_${filt}_${fact}_clamplocal.png

Image

convert $infile -filter lanczos -resize ${fact}% ${inname}_lanczos_${fact}.png

Image

compare -metric rmse ${inname}_lanczos_${fact}.png ${inname}_${filt}_${fact}_clamplocal.png null:
288.598 (0.00440373)




infile="house3b.png"
inname=`convert $infile -format "%t" info:`
filt="triangle"
fact=150
convert $infile \
\( -clone 0 -filter lanczos -resize $fact% \) \
\( -clone 0 -statistic minimum 3x3 -filter $filt -resize $fact% \) \
\( -clone 0 -statistic maximum 3x3 -filter $filt -resize $fact% \) \
\( -clone 1 -clone 2 -compose lighten -composite \
-clone 3 -compose darken -composite \) \
-delete 0-3 ${inname}_${filt}_${fact}_clamplocal.png

Image

convert $infile -filter lanczos -resize ${fact}% ${inname}_lanczos_${fact}.png

Image

compare -metric rmse ${inname}_lanczos_${fact}.png ${inname}_${filt}_${fact}_clamplocal.png null:
315.3 (0.00481116)

Re: halo minimization by local min/max smooth clamping

Posted: 2011-04-03T16:32:26-07:00
by magick
Which option are you talking about? There is no specific -lighten or -darken option.

Re: halo minimization by local min/max smooth clamping

Posted: 2011-04-03T16:37:24-07:00
by NicolasRobidoux
magick wrote:Which option are you talking about? There is no specific -lighten or -darken option.
In Fred's code above (thank you, Fred) he uses "-compose lighten".

Re: halo minimization by local min/max smooth clamping

Posted: 2011-04-03T16:54:13-07:00
by fmw42
NicolasRobidoux wrote:Does lighten/darken only affect the luminance based on the luminance, or does it work channel by channel?
My understanding is channel by channel. But you can ask Anthony to be sure.

see http://www.imagemagick.org/Usage/compose/#lighten and the comment:


Unfortunately these operators work on each RGB channel separately, and as such this could result in some color distortion, especially near edges of highly contrasting colors.

Re: halo minimization by local min/max smooth clamping

Posted: 2011-04-03T16:55:00-07:00
by fmw42
magick wrote:Which option are you talking about? There is no specific -lighten or -darken option.
-compose lighten/darken -composite

Re: halo minimization by local min/max smooth clamping

Posted: 2011-04-03T17:22:09-07:00
by NicolasRobidoux
When I have a minute, I'll do tests with a larger enlargement ratio (cropping smaller some pieces of the "house" test picture, and also using the rose: picture).

With an enlargement ratio of 1.5, it is hard to see halos: They are less than one pixel wide. The RMSE makes it clear that there is a difference. But it certainly is not obviously visible.

The good news to me is that the scheme does not add obvious artifacts. Fingers crossed.

Re: halo minimization by local min/max smooth clamping

Posted: 2011-04-03T19:15:45-07:00
by NicolasRobidoux
At high enlargement ratios, clamp-locally does correct some of the worst cases of over/undershoot but it occasionally gives a "pressed against the glass" look to the places where the clamping is "on" (because it creates "flat top" plateaus, at least with bilinear and hermite; when I have time I'll see if it's as noticeable with LBB). What this suggests to me is that the clamped version should not be taken straight, but "on ice" (say, 50% clamped + 50% unclamped).

Look in Lena's hair at 800%. (Elsewhere, too.)

Not too bad for a start.

Re: halo minimization by local min/max smooth clamping

Posted: 2011-04-03T20:28:51-07:00
by NicolasRobidoux

Code: Select all

convert rose: \
\( -clone 0 -filter lanczos -resize 1800% \) \
\( -clone 0 -statistic minimum 3x3 -filter hermite -resize 1800% \) \
\( -clone 0 -statistic maximum 3x3 -filter hermite -resize 1800% \) \
\( -clone 1 -clone 2 -compose lighten -composite \
-clone 3 -compose darken -composite \) \
-delete 0-3 rose_hermite_clamplocal.png

filt="triangle"
convert rose: \
\( -clone 0 -filter lanczos -resize 1800% \) \
\( -clone 0 -statistic minimum 3x3 -filter triangle -resize 1800% \) \
\( -clone 0 -statistic maximum 3x3 -filter triangle -resize 1800% \) \
\( -clone 1 -clone 2 -compose lighten -composite \
-clone 3 -compose darken -composite \) \
-delete 0-3 rose_triangle_clamplocal.png

convert rose: -filter lanczos -resize 1800% rose_lanczos.png
makes really clear what this does.

Comment: I think that this should be applied to the luminance channel, not to chrominance. (Later.)

Re: halo minimization by local min/max smooth clamping

Posted: 2011-04-03T22:07:50-07:00
by fmw42
Comment: I think that this should be applied to the luminance channel, not to chrominance. (Later.)
It is being applied to the RGB channels. If you only want it applied to the luminance channel, then what colorspace do you want to apply it to and I will set that up.

see colorspace table: http://www.imagemagick.org/script/comma ... colorspace

Do you want to convert first to Rec601YCbCr, Rec709YCbCr, YCC, or YCbCr (or HSL or HSB)?

Re: halo minimization by local min/max smooth clamping

Posted: 2011-04-03T22:28:15-07:00
by NicolasRobidoux
Pardon my ignorance Fred:

Ideally, I'd like a conversion to a linear format with a luminance (intensity) channel. Is there a "standard" one?

Do the interpolation/processing in that format, only clamping the luminance channel. Then back to sRGB, say.

Makes sense?

(I'll need to check that the conversion is not lossy because of clamping in the conversion. My oh my. So many details to check all the time. Of course, everything is safe if using floating point.)

Re: halo minimization by local min/max smooth clamping

Posted: 2011-04-04T09:38:53-07:00
by fmw42
NicolasRobidoux wrote:Pardon my ignorance Fred:

Ideally, I'd like a conversion to a linear format with a luminance (instensity) channel. Is there a "standard" one?

Do the interpolation/processing in that format, only clamping the luminance channel. Then back to sRGB, say.

Makes sense?

(I'll need to check that the conversion is not lossy because of clamping in the conversion. My oh my. So many details to check all the time. Of course, everything is safe if using floating point.)

That processing was what I had in mind. It was just deciding which YCbCr colorspace to use. I know little about them. I believe that one of the Rec formats ( probably Rec709) is what is preferable as a digital standard, but I would have to look into this myself.

I don't know that any of those are non-linear. You would have to look at the code to be sure.

see
http://en.wikipedia.org/wiki/YCbCr Y'CbCr is non-linear and YCbCr is linear, I believe. YCC may be non-linear in IM. see http://www.imagemagick.org/script/comma ... colorspace

I will set it up this afternoon with Rec709YCbCr, but any of the others can easily be used or tried.

Re: halo minimization by local min/max smooth clamping

Posted: 2011-04-04T15:18:50-07:00
by fmw42
Processing Luminance in Rec709YCbCr

Code: Select all

infile="rose:"
fact=1800
convert $infile -filter lanczos -resize ${fact}% rose_lanczos_${fact}.png
Triangle/Bilinear

Code: Select all

infile="rose:"
filt="triangle"
fact=1800
convert $infile -colorspace Rec709YCbCr -separate \
\( -clone 0 -filter lanczos -resize $fact% \) \
\( -clone 0 -statistic minimum 3x3 -filter $filt -resize $fact% \) \
\( -clone 0 -statistic maximum 3x3 -filter $filt -resize $fact% \) \
\( -clone 3 -clone 4 -compose lighten -composite \
-clone 5 -compose darken -composite \) \
\( -clone 1 -filter lanczos -resize $fact% \) \
\( -clone 2 -filter lanczos -resize $fact% \) \
-delete 0-5 -set colorspace Rec709YCbCr -combine \
-colorspace RGB rose_${filt}_${fact}_clamplocal_ycbcr.png

compare -metric rmse rose_lanczos_${fact}.png rose_${filt}_${fact}_clamplocal_ycbcr.png null:
150.326 (0.00229383)


Hermite:

Code: Select all

infile="rose:"
filt="hermite"
fact=1800
convert $infile -colorspace Rec709YCbCr -separate \
\( -clone 0 -filter lanczos -resize $fact% \) \
\( -clone 0 -statistic minimum 3x3 -filter $filt -resize $fact% \) \
\( -clone 0 -statistic maximum 3x3 -filter $filt -resize $fact% \) \
\( -clone 3 -clone 4 -compose lighten -composite \
-clone 5 -compose darken -composite \) \
\( -clone 1 -filter lanczos -resize $fact% \) \
\( -clone 2 -filter lanczos -resize $fact% \) \
-delete 0-5 -set colorspace Rec709YCbCr -combine \
-colorspace RGB rose_${filt}_${fact}_clamplocal_ycbcr.png

compare -metric rmse rose_lanczos_${fact}.png rose_${filt}_${fact}_clamplocal_ycbcr.png null:
151.032 (0.0023046)

Re: halo minimization by local min/max smooth clamping

Posted: 2011-04-04T23:32:42-07:00
by anthony
fmw42 wrote:
NicolasRobidoux wrote:Does lighten/darken only affect the luminance based on the luminance, or does it work channel by channel?
My understanding is channel by channel. But you can ask Anthony to be sure.

see http://www.imagemagick.org/Usage/compose/#lighten and the comment:

Unfortunately these operators work on each RGB channel separately, and as such this could result in some color distortion, especially near edges of highly contrasting colors.
That is how they are working, as they are defined by the SVG composition operator reference.
When transparency is involved, color values are weighted by their alpha, and alpha is given 'over' blending (screen).

I did make a change so that if the -channel 'Sync' is turned off. EG: set -channel RGB then no alpha weighting, and alpha itself works on a 'lighten' (maximum) composition. that is 'no-sync' flag in channel, and no syncronization of channels are performed. BUT in either case it is still purely channel by channel.

I would like to add a Lighten_Intensity and Darken_Intensity option which will select the whole pixel of one image or the other based in the 'intensity' of the colors. I do this for example in morphology with the experimental intensity variants.. http://www.imagemagick.org/Usage/morphology/#intensity

This should not take much effort to add, if you want it! Takes longer to document it though!

Of course none of the above cases matter if you apply it to greyscale images.

Or even binary images. In which cans Lighten and Darken can be thought of as being Mathematical Set Operators...
http://www.imagemagick.org/Usage/compose/#set_theory


Currently the the only way to do intensity lighten, is to craete two grayscale images, lighten them together,
compare them against one of the greyscale images to generate a mask, then use that mask to select pixels on the original image.

Code: Select all

convert  image1.png image2.png \
             \( -clone 0--1 -colorspace Gray \
                 \( -clone 0--1 -compose Lighten -composite \) \
                 -delete 1 -compose Difference -composite -threshold 0 \
              \) -compose Src -composite     intensity_lightened.png
Horrible isn't it! You can get Darken simply by inverting the mask or changing -delete 1 to -delete 0

Of course how do you actually compare images with transparency. Is a semi-transparent white equivalent to
a grey?

Re: halo minimization by local min/max smooth clamping

Posted: 2011-04-05T11:11:51-07:00
by NicolasRobidoux
anthony wrote:...
I would like to add a Lighten_Intensity and Darken_Intensity option which will select the whole pixel of one image or the other based in the 'intensity' of the colors. I do this for example in morphology with the experimental intensity variants.. http://www.imagemagick.org/Usage/morphology/#intensity...
I would love this!

-----

IMNSHO ("...Not So Humble..."), the default behavior should be that the alpha channel does not contribute to the computation and is simply copied over from one the two input images (the first one, say).

(If the behavior is that the non-alpha channels and the alpha channel have the operation applied to them independently, the above can be emulated by setting the alpha channel of one of the two input images to "MINVAL" (Lighten) or "MAXVAL" (Darken), in other words by making the image completely opaque or completely transparent.)