Page 1 of 1

Clipping Color Range via CLUT

Posted: 2013-02-28T07:01:22-07:00
by sunape
Hi everyone,

This is what I'm trying to do:
For each color channel in an 24bit RGB image, replace all values below 16 with 16 and all values above 235 with 235.

What I tried:
I made a color lookup table ("clut.pgm", one row, 256 values). No values under 16 or above 235 are included in the table, all other values are sequential (example 8->16, 21->21, 45->45, 240->235).

I ran it through convert:

Code: Select all

convert 01429_sunsetinedinburgh_1280x800.jpg clut.pgm -clut output.png
Now, when I'm checking the histogram of output.png, I still see a lot of color values < 16. If I run -clut twice, though, these stray pixel values are gone.

Code: Select all

convert 01429_sunsetinedinburgh_1280x800.jpg clut.pgm -clut clut.pgm -clut output.png
Now, I do need a 100% surefire way to eliminate all values below 16 and above 235, so that second option is not good either (what if, for some images, I need to run it three times?).

Is this a bug? It has nothing to do with input/output formats (I tried). Any other ways to do with I'm trying to do?

EDIT: Sample data is available here.


EDIT2: ... and I found the solution myself. My CLUT was wrong (0x0D 0x0A in PGM instead of 0x0D) :-/. Duh... Can any moderator delete this thread?
..

Re: Clipping Color Range via CLUT

Posted: 2013-02-28T07:26:28-07:00
by snibgo
What IM version? What platform?

So, clut.pgm contains 256 values. The first 16 values are 16, the last 21 are 235, and values 17 to 234 are set to 17 to 234. That should work. You can verify the values are correct:

Code: Select all

convert clut.pgm txt:
There are other ways to achieve this, eg with threshold, then turning black or white to the apropriate shade of gray. I would expect clut to be faster.

Re: Clipping Color Range via CLUT

Posted: 2013-03-14T16:37:28-07:00
by anthony
Use a -level and +level, to clip the color range...

See these effects in the example on "burning and clipping"
http://www.imagemagick.org/Usage/basics ... um_effects

Warning IMv7 is HDRI by default, so you will need to include a "-clamp" operation.