This is Interesting: Free Magazines for Graphics designers and webmasters  


Home > Archive > PainShop Pro Scripting > August 2007 > How to make a python script to remap pixel by pixel colors





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author How to make a python script to remap pixel by pixel colors
Dario de Judicibus

2007-08-08, 6:31 pm

Question is: how can I convert a 16-bit grayscale TIFF file to a 8-bit
paletted color map so that I have a biunivocal corrispondence between a
grayscale value and a color?

For example:

0 (76) -> (0, 76, 255)
0 (123) -> (0, 123, 255)
1 (174) -> (255, 174, 1)
1 (242) -> (255, 242, 1)
2 (112) -> (112, 2, 255)

Note that the target color is totally different from source grayscale value.
Any converson logics can be applied.

I suppose I have to use a script, but which functions? How can I read all
pixels of a 16-bit grayscale file and create a new file with a mapping
algorithm? That is:

get source image (16bits Gray) size
create empty target image (8bits RGB) same size
for each pixel in source image
read source image pixel
get pixel grayscale values (16bits)
convert to a specific color according to some logics
write target image pixel
end

Thank you in advance

--
Dario de Judicibus - Rome, Italy (EU)
Site: http://www.dejudicibus.it
Blog: http://lindipendente.splinder.com
Book: http://www.lalamanera.it


Spandex Rutabaga

2007-08-08, 6:31 pm

Dario de Judicibus wrote:
>
> Question is: how can I convert a 16-bit grayscale TIFF file to a 8-bit
> paletted color map so that I have a biunivocal corrispondence between a
> grayscale value and a color?


For 8-bit-per-channel images you can use Gary Barton's Gradient Map
script. It's here http://pixelnook.home.comcast.net/TheLab.html.
It fills a 256-pixel-wide temporary image with a gradient and uses
the grey level of your image as the horizontal coordinate into this
image to retrieve the color which should be used for the grey level.

You have a problem using this technique for 16-bit-per-channel images
because the limit on any dimension of an image is 32,767 and not the
65,535 you would need. You can get around this in one of two ways.
First, you could use not one but two auxillary images. Second, you
could continue to use the 256 pixel wide image but scale all your
grey values by dividing by 256, using the remainder of the division
to linearly interpolate up to 256 color levels between any two
adjacent color values in your gradient image.
Dario de Judicibus

2007-08-08, 6:31 pm


"Spandex Rutabaga" <SpRu@agabatur.xednaps> ha scritto nel messaggio
news:46B9E616.97A7EDF0@agabatur.xednaps...
| For 8-bit-per-channel images you can use Gary Barton's Gradient Map
| script. It's here http://pixelnook.home.comcast.net/TheLab.html.
| It fills a 256-pixel-wide temporary image with a gradient and uses
| the grey level of your image as the horizontal coordinate into this
| image to retrieve the color which should be used for the grey level.
|
| You have a problem using this technique for 16-bit-per-channel images
| because the limit on any dimension of an image is 32,767 and not the
| 65,535 you would need. You can get around this in one of two ways.
| First, you could use not one but two auxillary images. Second, you
| could continue to use the 256 pixel wide image but scale all your
| grey values by dividing by 256, using the remainder of the division
| to linearly interpolate up to 256 color levels between any two
| adjacent color values in your gradient image.

Thank you for useful suggestions and referencing a useful script. I still
have some problems to manage 16bit and 48bit files. It looks like PSP XI
support is quite poor. For example, the material palette does not hadle
2byte colours.... If I peek a colour from a 16bit gray image (for example
0(123)) and I fill it in another image, I just get 0(0).

DdJ


Spandex Rutabaga

2007-08-08, 6:31 pm

Dario de Judicibus wrote:
>
> "Spandex Rutabaga" <SpRu@agabatur.xednaps> ha scritto nel messaggio
> news:46B9E616.97A7EDF0@agabatur.xednaps...
> | For 8-bit-per-channel images you can use Gary Barton's Gradient Map
> | script. It's here http://pixelnook.home.comcast.net/TheLab.html.
> | It fills a 256-pixel-wide temporary image with a gradient and uses
> | the grey level of your image as the horizontal coordinate into this
> | image to retrieve the color which should be used for the grey level.
> |
> | You have a problem using this technique for 16-bit-per-channel images
> | because the limit on any dimension of an image is 32,767 and not the
> | 65,535 you would need. You can get around this in one of two ways.
> | First, you could use not one but two auxillary images. Second, you
> | could continue to use the 256 pixel wide image but scale all your
> | grey values by dividing by 256, using the remainder of the division
> | to linearly interpolate up to 256 color levels between any two
> | adjacent color values in your gradient image.
>
> Thank you for useful suggestions and referencing a useful script. I still
> have some problems to manage 16bit and 48bit files. It looks like PSP XI
> support is quite poor. For example, the material palette does not hadle
> 2byte colours.... If I peek a colour from a 16bit gray image (for example
> 0(123)) and I fill it in another image, I just get 0(0).


Well, I'm afraid I can't help any strangeness with PSPP XI 16-bit
support. I'm not especially surprised that things don't work right.

However, setting all that aside, ask yourself if you really need
a 16-bit-per-channel image just to get your final gradient mapped
image. I assume this latter image is for visualizing some kind of
height trends. In most of the RGB color space your eye cannot detect
changes as small as 1 part in 255. For certain colors (e.g. two of
R, G and B very dark and one very bright) you might not be able to
see steps of 10 parts in 255. Your monitor doesn't display more than
8 bits per channel. So, for your final purposes are you sure it is
not enough to stretch the height values, convert to 8 bit and
gradient map? If so, you already have a solution and don't need
to suffer any more pain.
Dario de Judicibus

2007-08-08, 6:31 pm


"Spandex Rutabaga" <SpRu@agabatur.xednaps> ha scritto nel messaggio
news:46B9F656.D8BA6415@agabatur.xednaps...

| However, setting all that aside, ask yourself if you really need
| a 16-bit-per-channel image just to get your final gradient mapped
| image.

Not a matter of needing... ;-) They are generated by a satellite... Not my
choice.

DdJ


Spandex Rutabaga

2007-08-08, 10:20 pm

Dario de Judicibus wrote:
>
> "Spandex Rutabaga" <SpRu@agabatur.xednaps> ha scritto nel messaggio
> news:46B9F656.D8BA6415@agabatur.xednaps...
>
> | However, setting all that aside, ask yourself if you really need
> | a 16-bit-per-channel image just to get your final gradient mapped
> | image.
>
> Not a matter of needing... ;-) They are generated by a satellite... Not my
> choice.


If in PSPP XI there is no way to specify a 16-bit RGB color for
a pixel then no amount of scripting will help you.

You could try writing a file in some simple format like the
ASCII version of Portable Bitmap and then writing your own
program to convert this to a gradient mapped image in the same
format. I don't know if PBM supports a 16 bit per channel color
depth though. You could also read the TIFF file using your own
program and the free TIFF library and then do the gradient
mapping and writing of the TIFF result. You can't use Photoshop
since it actually uses 15-bit color, not 16-bit. However, you
might be able to this all with the image processing functions
in Matlab, which is popular in the academic environment.
Sponsored Links


Copyright 2003 - 2009 forum4designers.com  Software forum  Computer Hardware reviews