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

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
Forum membership is Free!  Click Join to sign-up
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 Read TIF file as array
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

esprd

10 Posts

Posted - Jul 24 2025 :  10:53:53  Show Profile  Reply
Hi,

I have TIF files generated by python program containing "integer values" (some are negative) for each "pixel" instead of real color value.
In fact, the data they contain are more "array of data" than picture.

Is there a way to get the values stored in the files with ImageEn ?

I've loaded the file in a TImageEnMView, but then I'm stuck to get the values.

Best regards

ep

atrust

6 Posts

Posted - Jul 24 2025 :  22:37:48  Show Profile  Reply
Hi, could you please share the Python code that generates that kind of TIF file?
Go to Top of Page

esprd

10 Posts

Posted - Jul 25 2025 :  12:04:26  Show Profile  Reply
Hi,

Here is an example of the code generating the file :

//------------------------------------
import numpy as np
import tifffile

# Generate 2D array of shape (2000, 3000) with int32 type
# this example generates random values from -1500 to 1500
labels_table = np.random.randint(
    low=-1500,
    high=1500,
    size=(2000, 3000),
    dtype=np.int32,
)

# Write to TIFF file
tifffile.imwrite(
    "labels.tif",
    labels_table,
    dtype=np.int32,
    photometric="minisblack",
    metadata=None,
)

//------------------------------------

ep
Go to Top of Page

atrust

6 Posts

Posted - Jul 26 2025 :  19:31:20  Show Profile  Reply




Hi,
You can use ImageEnView to load the TIFF file and obtain its width and height. This tells you how many rows the image has, and how many integer values are in each row.
However, to read the actual integer values directly, I suggest using a separate file-reading method, like TMemoryStream, to load the TIFF file as raw bytes.
Then, locate the offset where stores the data block "tifffile.py". The actual 32-bit integer values start 16 bytes after that position (as indicated by the red arrow).
From there, you can read the data directly as an array of integers.
Go to Top of Page

xequte

39097 Posts

Posted - Jul 27 2025 :  19:13:01  Show Profile  Reply
Yes, that is a good way if it is not a true TIFF format.

What PixelFomat does ImageEn use if you set NativePixelFormat to true before loading?

http://www.imageen.com/help/TIOParams.NativePixelFormat.html

Also, can you attach an example file?


Nigel
Xequte Software
www.imageen.com
Go to Top of Page

esprd

10 Posts

Posted - Jul 28 2025 :  01:53:35  Show Profile  Reply
Hi Nigel,

This code gives:

procedure TForm1.Button2Click(Sender: TObject);
var
  iePixelF : TIePixelFormat ;

begin
  if OpenImageEnDialog1.Execute then
  begin
    ImageEnView1.IO.Params.NativePixelFormat := true ;
    ImageEnView1.IO.LoadFromFile( 'OpenImageEnDialog1.FileName' ) ;
    iePixelF := ImageEnView1.IEBitmap.PixelFormat ;
  end;

end;


iePixelF = ie24RGB

Attached an example of file.

Regards

attach/esprd/202572815134_Example.TIF

ep
Go to Top of Page

xequte

39097 Posts

Posted - Jul 28 2025 :  23:35:37  Show Profile  Reply
Hi

So, ImageEn does not support this type of format so you would need to process the pixels using another method.

Alternatively if you could output your TIFF as:

BitsPerSample = 32
SamplesPerPixel = 1
SampleFormat = SampleFmt_IEEEFP
PhotometricInterpretation = Photomet_BlackIsZero_ID

Then ImageEn could load the image natively as ie32f.




Nigel
Xequte Software
www.imageen.com
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
Jump To: