ImageEn for Delphi and C++ Builder ImageEn for Delphi and C++ Builder

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 Making 16 bit grayscale TIF from raw memory buffer

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

View 
UserName:
Password:
Format  Bold Italicized Underline  Align Left Centered Align Right  Horizontal Rule  Insert Hyperlink   Browse for an image to attach to your post Browse for a zip to attach to your post Insert Code  Insert Quote Insert List
   
Message 

 

Emoji
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Black Eye [B)]
Frown [:(] Shocked [:0] Angry [:(!] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
wshowalter Posted - Jan 07 2013 : 15:17:01
I just got your ImageEn software, so I am fairly unfamiliar with it, but I'm wondering if anyone can point me in the right direction to do the following:

I have a 12 bit grayscale image in a memory array that came in from a camera. There is no format for the data, it is just a buffer filled with 16 bit words that represent the camera image values 0-4095. I need to be able to save this as a lossless, LZW compressed, 16 bit grayscale TIF file for image processing elsewhere.

I've been able to create and properly display my image in a TImageEnView graphic, and have saved it to a TIF file. It improperly saves in a 48 bit format, and when I read it back into another TImageEnView and display that, the image is not correct (mangled), so I am sure I am not forming the TIF properly.

How should I proceed with this? My sample code so far is:

const
TheWidth = 200;
TheHeight = 200;
var
x, y : integer;
TestBitmap : array[ 0..(TheWidth - 1), 0..(TheHeight - 1) ] of word;
begin
{TestBitmap gets preloaded with a very simple image pattern of all black with a white line 1/3 of the way down.}
FillChar( TestBitMap, sizeof( TestBitMap ), 0 );

for x := 0 to TheWidth - 1 do
TestBitMap[ x, TheHeight div 3 ] := 65535;

{Now my attempt at getting the image in a TIF format...that fails...}
TheBitmap := TIEBitmap.Create( TheWidth, TheHeight, ie16g );
TheImageEnView.LegacyBitmap := false;

for y := 0 to TheHeight - 1 do
for x := 0 to TheWidth - 1 do
TheBitmap.Pixels_ie16g[ x, y ] := TestBitmap[ x, y ];

TheImageEnView.IEBitmap.AssignImage( TheBitmap );
TheImageEnView.Refresh;
{At this point, the image looks correct on screen.}


TheImageEnView.IO.SaveToFileTIFF( 'C:\TestImages\Test.tif' );
{At this point, the file result is a 48 bit image. How do I save this properly to a 16 bit grayscale, plus add lossless, LZW compression?}

Thanks,
Wayne Showalter
5   L A T E S T    R E P L I E S    (Newest First)
jcf Posted - Feb 17 2014 : 13:23:11
what about displaying a 16 bits histogram ?

hello
Uwe Posted - Jan 08 2013 : 11:56:33
From the help file:


TImageEnIO.NativePixelFormat

Declaration

property NativePixelFormat:boolean;


Description

By setting this property to True, you disable the conversion of paletted images, gray scale and all other formats to 24 bit or 1 bit.
By default, ImageEn converts all paletted, gray scale images and other formats to 24 bit (true color). Only black/white images are stored in the original format with 1 bit per pixel.
LegacyBitmap must be False.

Note that setting NativePixelFormat=True, you will not be able to execute some image processing operations.

For example, if you have a 16 bit gray scale TIFF and you want to work with 16 bit gray scale pixels, you have to write this before load the image:
ImageEnView1.LegacyBitmap:=False; // do not use Tbitmap
ImageEnView1.IO.NativePixelFormat:=true; // leave original pixel format

Now you can read pixels using:
word = ImageEnView1.IEBitmap. Pixels_ie16g[x,y];
wshowalter Posted - Jan 08 2013 : 10:11:35
OK, I think I am saving a 16 bit grayscale image properly. At least all indications are that this is so. However, when I turn right around and load the image back in, it is coming in as PixelFormat = ie24RGB, which is wrong.

There appears to be a crack in the TIFFReadStream routine that incorrectly detects 16 bit grayscale as 24 bit RGB. I'm doing a Load immediately following the Save line.

Shouldn't an image saved as 16 bit grayscale keep its PixelFormat when loaded? Has anyone experienced this issue?

Cheers,
Wayne
wshowalter Posted - Jan 07 2013 : 17:49:35
Thanks, that helped. Actually I needed a minor modification to the above:

ImageEnView1.IO.Params.BitsPerSample := 16; (not 8)

Cheers,
Wayne
w2m Posted - Jan 07 2013 : 16:06:29
This is just a guess:

// saves 16-bit grayscale bitmap
ImageEnView1.IO.Params.BitsPerSample := 8;
ImageEnView1.IO.Params.SamplesPerPixel := 1;
Specifies the compression type for TIFF image format.
ImageEnView1.IO.Params.TIFF_Compression := ioTIFF_LZW;
...
TheImageEnView.IO.SaveToFileTIFF( 'C:\TestImages\Test.tif' );

William Miller
Email: w2m@frontiernet.net
EBook: http://www.imageen.com/ebook/
Apprehend: http://www.frontiernet.net/~w2m/index.html