16bit tif

Hello,

I use ROOT 5.16 to analyze medical images. Usually I work with 8bit gray scale pictures using the TASImage package which works fine. Now I want to use a 16bit image format (tif). Is TASImage able to deal with 16bit tif format?
For my 8bit pictures I usually use the following code to access the individual pixel values:

TASImage *tifImg = new TASImage("…/example.tif");
UInt_t *pntArray = tifImg-> GetAgbArray();

Is there any similar method foreseen to access 16bit image pixel values?

[quote=“Luke”]Hello,

I use ROOT 5.16 to analyze medical images. Usually I work with 8bit gray scale pictures using the TASImage package which works fine. Now I want to use a 16bit image format (tif). Is TASImage able to deal with 16bit tif format?
For my 8bit pictures I usually use the following code to access the individual pixel values:

TASImage *tifImg = new TASImage("…/example.tif");
UInt_t *pntArray = tifImg-> GetAgbArray();

Is there any similar method foreseen to access 16bit image pixel values?[/quote]

do you mean 16 bit gray image?

Yes, I mean 16 bit gray images. I have add one as attachment for you.

strange, I can’t get attached image.

Luke, you can use “vector images”.
Vector image is an image which colors are defined by doubles (in the range from 0 to 1)
with correspondent color palette.
For gray images, it’s “natural” to measure a color in luminosity units
(luminosity specifies a shade of gray).
Luminosity can be calculated as

 l = (0.2126*R + 0.7152*G + 0.0722*B)/256;

Using this formula and iterating through all RGB colors in an image you can convert
RGB values to doubles and create correspondent color palette.

Regards. Valeriy

[quote=“Luke”]Yes, I mean 16 bit gray images. I have add one as attachment for you.[/quote]I do not see your file.
However, I would like to call your attention that with a small effort one can complement the ROOT classes with Qt classes:

doc.trolltech.com/4.3/qimage.htm … mage-files

It sounds, QImage class has no constrain you have been speaking about.
To confirm that, I need your file. In return, I can provide a small ROOT macro that demonstrates the outcome.

Thanks for your fast answers. I have add the attachment again. I hope you can open it now.
N98_0002.root (251 KB)

Please find the screen shot made with the ROOT macro and the file you had uploaded[code]void gray_image()
{
// Display image in a new canvas and pad.

TImage *img = TImage::Open(“N98_0002.tiff”);

if (!img) {
printf(“Could not create an image… exit\n”);
return;
}
img->Draw(“xxx”);
}[/code]This macro does require the ROOT TImage Qt-based plug-in compiled against of Qt 4.x ( trolltech.com/customers/coolapps )
This is to demonstrate the file format in question can be treated properly by Qt 4.x ( I did find Qt 3.x can not read it). The ROOT plugin in question is a part of Qt- Extension available from root.cern.ch/root/doc/RootDoc.html “26 ROOT/Qt Integration
Interfaces” This way your application are becoming Qt-addicted :unamused: though. Anyway, by some reason, you do not use the generic base class, namely TImage. You use the class concrete libAfter-based implementation. Why ? If you used the TImage then you may have switched between the different implementation ( afterImage / Qt) by providing the different TImage plug-ins via ROOT resource file “.rootrc”. You may not have required to change your code and re-compile it.

[quote=“Luke”]UInt_t *pntArray = tifImg-> GetAgbArray();

Is there any similar method foreseen to access 16bit image pixel values?[/quote]
Hello Luke, May I ask you a question to make sure I do understand your needs? The Argb array provides 8 bits precision for the gray images. Speaking about “similar” method, did you mean you agree to lose the precision your 16bit gray file contains or you meant you need a method to access the flat array of 16bits gray pixels. I.e. you want the array of “unsigned short”'s.
The short stand-alone Qt-4.x based code:

#include <qapplication.h> #include <QImage> int main( int argc, char **argv ) { QApplication app(argc, argv); QImage img("N98_0002.tiff"); // QPixmap img("N98_0002.tiff"); printf(" Image size %d x %d, depth=%d, numColor=%d\n", img.width(), img.height(),img.depth() , img.numColors()); const unsigned long *pixel = (const unsigned long *)img.bits(); for (int i =0; i< 20; i++) printf(" pixel = 0x%x\n", pixel[i]); return 0; }prints the ARgb array made from your tif file:

Image size 447 x 287, depth=32, numColor=0 pixel = 0xff737373 pixel = 0xff6f6f6f pixel = 0xff6f6f6f pixel = 0xff717171 pixel = 0xff6f6f6f pixel = 0xff6b6b6b pixel = 0xff6e6e6e pixel = 0xff737373 pixel = 0xff717171 pixel = 0xff717171 pixel = 0xff727272 pixel = 0xff707070 pixel = 0xff707070 pixel = 0xff727272 pixel = 0xff747474 pixel = 0xff747474 pixel = 0xff757575 pixel = 0xff747474 pixel = 0xff717171 pixel = 0xff717171The topic had been discussed elsewhere. Please, read, for example, lists.trolltech.com/qt-interest/ … 130-0.html (take in account it is 2 years old ) to see whether it is related to your needs.

Hi,
the printing above, like "pixel = 0xff727272 ", shows that QImage
internally transforms 16-bit gray tiff image into 8 -bit one.

To work with 16-bit grayscale format I suggest to use a vector image.
Luke, as far as I understood you have a camera which output is
2D array of 16-bit values (?).
You need to create an array of doubles (from camera output)
in the range [0, 1] and TImagePalette
root.cern.ch/root/html/TImagePalette.html
which makes correspondence between double values and colors.

Could you send me a file with camera output data (as text file)?
I’d like to prepare an example how to do it.

Regards. Valeriy

Hi Valery,

this thread is a bit old, but I couldn’t find the example. Have you made it?
If you need an 16 bit gray scale TIFF I can provide one for you, just let me know.

Regards,
Lazar.

Can this artis.inrialpes.fr/Software/TiffIO/ help ?

Hi Valeri,
thank you for the reply:

However I don’t feel comfortable with Qt. Is there any way to process 16 bit tiff images in ROOT without involving Qt?
The last post from Valeriy Onuchin sounded like there is :slight_smile:

Greetings,
Lazar.

Hi,
if you are working under win you can use native "The Windows Imaging Component"
microsoft.com/downloads/en/d … laylang=en
to work with 16 bit tiffs

Regards. Valeriy

++
Check this post
varioustopics.com/image-proc … tiffs.html

Hi Valeriy,

thank you for the reply!
I use ubuntu 10.10.
I tried libtiff as suggested but it shows some bizarre error:

although both the arguments should be:

[quote] TIFF* TIFFOpen(const char *filename, const char *mode) [/quote] (extract from the man page)
any comment or should I look for a libtiff forum?

Thanks,
Lazar.

The error

[quote]
Error: Function TIFFOpen(“foo.tif”, “w”) is not defined in current scope [/quote]

is quite trivial. This means, you did not include header, or this header does not declare TIFFOpen (new/older version?)

P.S. TIFFOpen is declared in a tiffio.h.

I wish it would be so trivial, however the header (tiffio.h) is included (but of course :smiley:) and it contains the declaration on line 427:[quote]extern TIFF* TIFFOpen(const char*, const char*);[/quote]
following is the code I use:[code]
#include “tiffio.h”

void imanali()
{
gSystem->Load(“libtiffxx”);
TIFF* tif = TIFFOpen(“foo.tif”, “w”);
}
[/code]I also tried loading libtiff with gSystem but it made no difference. The error persist :unamused:

Did you do this from CINT? If the answer is ‘yes’, then you should create and load the Root/Cint dictionary first

I was talking about compiled program, not the macro executed by CINT.
Try to compile your macro .L macro_name.C++ and this will work.