From: Roger O on
I am using the C API to manipulate some image items in Tk. I have two
types of photos that I need to use: one is an 8-bit and the other a 16-
bit greyscale image. I am updating the contents via the
Tk_PhotoPutBlock() C function. For the 8-bit photo, all is working
fine. However, the 16-bit image is not quite correct.

My question is, should I be able to specify a 16-bit greyscale image
to tk? I see that in the Tk source, if a PGM file has a max pixel
value of >255, the library complains. Of course, this is exactly what
I have... Is it just that the library does not support this, or is
this not possible to specify via the Tk_PhotoPutBlock()/
Tk_PhotoImageBlock interface?

My parameters look like:

Tk_PhotoImageBlock r_blimage;

r_blimage.pixelPtr = myProfile;
r_blimage.width = rangeWidth;
r_blimage.height = numScans;
r_blimage.pitch = rangeWidth * 2;
r_blimage.pixelSize = 2;
r_blimage.offset[0] = r_blimage.offset[1] = r_blimage.offset[1] = 0;

The format of the data, in PGM syntax, is:

P5
rangeWidth numScans
65535

If the answer is that this interface does not support a 16-bit
greyscale image, what are my best options? I know I could truncate the
image to be 8-bit. But I really want the 16-bit resolution for this
use. It is an interface to a 3D camera/laser that will be used in
image processing. So, resolution is important. The values are really
heights. I could convert them to a non-greyscale format if that works.

Any constructive suggestions are welcome.

--
Roger Oberholtzer
From: Donal K. Fellows on
On 26 Jan, 17:47, Roger O <roger.oberholt...(a)gmail.com> wrote:
> I am using the C API to manipulate some image items in Tk. I have two
> types of photos that I need to use: one is an 8-bit and the other a 16-
> bit greyscale image. I am updating the contents via the
> Tk_PhotoPutBlock() C function. For the 8-bit photo, all is working
> fine. However, the 16-bit image is not quite correct.

The photo image type has a datamodel of RGBA, with 8 bits per channel
per pixel. This is very deeply hard-coded in the code, so changing is
impractical. Thus, you need to make your own image type. (Tk supports
two image types natively - photo and bitmap - but it's a fully
pluggable architecture at the C level.)

Donal.
From: Paul Obermeier on
Hi Roger,

You may take a look at the sources of tkImg.
It has a PPM parser, which supports 8-bit and 16-bit images.
It performs tone-mapping of the 16-bit image before sending it to Tk.

Paul

Roger O wrote:
> I am using the C API to manipulate some image items in Tk. I have two
> types of photos that I need to use: one is an 8-bit and the other a 16-
> bit greyscale image. I am updating the contents via the
> Tk_PhotoPutBlock() C function. For the 8-bit photo, all is working
> fine. However, the 16-bit image is not quite correct.
>
> My question is, should I be able to specify a 16-bit greyscale image
> to tk? I see that in the Tk source, if a PGM file has a max pixel
> value of >255, the library complains. Of course, this is exactly what
> I have... Is it just that the library does not support this, or is
> this not possible to specify via the Tk_PhotoPutBlock()/
> Tk_PhotoImageBlock interface?
>
> My parameters look like:
>
> Tk_PhotoImageBlock r_blimage;
>
> r_blimage.pixelPtr = myProfile;
> r_blimage.width = rangeWidth;
> r_blimage.height = numScans;
> r_blimage.pitch = rangeWidth * 2;
> r_blimage.pixelSize = 2;
> r_blimage.offset[0] = r_blimage.offset[1] = r_blimage.offset[1] = 0;
>
> The format of the data, in PGM syntax, is:
>
> P5
> rangeWidth numScans
> 65535
>
> If the answer is that this interface does not support a 16-bit
> greyscale image, what are my best options? I know I could truncate the
> image to be 8-bit. But I really want the 16-bit resolution for this
> use. It is an interface to a 3D camera/laser that will be used in
> image processing. So, resolution is important. The values are really
> heights. I could convert them to a non-greyscale format if that works.
>
> Any constructive suggestions are welcome.
>
> --
> Roger Oberholtzer
From: Christian Gollwitzer on
Hi Roger,

Roger O schrieb:
> The format of the data, in PGM syntax, is:
>
> P5
> rangeWidth numScans
> 65535
>
> If the answer is that this interface does not support a 16-bit
> greyscale image, what are my best options? I know I could truncate the
> image to be 8-bit. But I really want the 16-bit resolution for this
> use. It is an interface to a 3D camera/laser that will be used in
> image processing.

I've written a similar tool 3D scan data (from an X-ray device). Tk
photo can't do 16 bit, but it also can't do any interesting image
processing. So in my case, I have an underlying C++ object (interfaced
to Tcl using SWIG) which does all the image processing stuff in 16bit
and 32bit float. Then there is a simple function (getimage), which
copies the data into a photo image using TkPhotoPutBlock, the data is
truncated to 8bit in a suitable way before - specifically it is a linear
mapping from a subrange, which can be selected by the user interactively.

Another option - maybe - is the use of ImageMagick. If compiled with
16bit support, it can handle this data quite nicely. I don't know about
the tcl interface, though.

Christian
From: Roger O on

In this case, I use openCV the and intel Performance Primitives
library in C to do the image processing. openCV has a python and a
perl interface via SWIG. There is none for Tcl. I have been
considering looking at the SWIG .i files for python to see how much
work there would be to make a Tcl interface descrition for SWIG. Until
that time, all is in C. Which is not really a problem. Our higher
level library for all this is available in Tcl via SWIG. And that is
the level at which we process images.

The Tk part is mainly a viewer that will be used when setting up the
cameras. However, one of the 'images' is really a high precision (0.25
mm vertical resolution) elevation profile where each 16-bit pixel
value is the elevation. The image rows are 1536 pixels wide and occur
at 500 or 1000 Hz. For sanity reasons, a number of rows are grouped
into the images under discussion here. When setting up the camera, we
need to magnify some of the elevation ranges to see that they are
being detected as expected. I think my best solution will be to use a
Tk slider set to select the elevation ranges from a 16-bit range of
values, and then recalculate an 8-bit image from the original 16-bit
data in the C code, updating the viewed image with Tk_PhotoPutBlock().

I think I will try to stick with the core Tk 8-bit photo if I can.