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
 GIS TIFF Elevation File - Pixel Level Access
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

HMArnold

USA
23 Posts

Posted - Oct 10 2019 :  11:27:03  Show Profile  Reply
I'm using GIS Elevation raster files in TIFF format, and am trying to access the individual pixel values.

Using ImageEn version 8.7.0

I'm attaching what one looks like when loaded into ArcMap, but the forum server won't allow me to attach an example TIFF file of 7mb.

As I understand, it is essentially a black and white image with the values for each pixel being the elevation of the ground at that spot. Since this area is along the coast, the values in the file I'm working with are between 17 and 59 meters.

Using a normal image viewer, the TIFF looks white, I assume because of the small values.

Once loaded using ImageEN, the "Bitmap.PixelFormat" comes back as "pf24bit".

The only 24 bit pixel access I see is "IEBitmap.ie24RGB[x,y]" that returns a "TRGB" value.

When I use this to read into the array, all values come back as 255 for Red, Green, and Blue.

I've also tried reading the 16 bit word values, but those all come back as the maximum, 65536

Has anyone been able to open one of these GIS TIFF files in ImageEn and access individual pixels? It would be a powerful tool.

Suggestions appreciated



Insert Image:

HM Arnold

xequte

38615 Posts

Posted - Oct 10 2019 :  18:28:32  Show Profile  Reply
Hi

Please set NativePixelFormat to true

https://www.imageen.com/help/TImageEnIO.NativePixelFormat.html

Then you can access the true pixel value, using the appropriate Pixels_ie* property for that PixelType

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

HMArnold

USA
23 Posts

Posted - Oct 10 2019 :  19:04:26  Show Profile  Reply
Nigel,

Thanks very much

I saw that in some of the other forum posts, and tried it, but get the attached message...

I have also tried it with the LegacyBitmap on and off - with and without the NativePixelFormat

Here is the code..


procedure TForm1.ScanButtonClick(Sender: TObject);
var x, y        : integer;
    PixelFormat : TPixelFormat;
    RGB         : TRGB;
    Value       : word;
begin
  (*Image.LegacyBitmap := false; *)
  Image.IO.NativePixelFormat := true;
  Image.IO.LoadFromFileTIFF(ImagePath);
  ListBox1.Items.Add('Size : '+IntToStr(Image.IEBitmap.Width)+'/'+IntToStr(Image.IEBitmap.Height));
  PixelFormat := Image.Bitmap.PixelFormat;
  case PixelFormat of
    pfDevice  : ListBox1.Items.Add('Pixel Format : pfDevice');
    pf1bit    : ListBox1.Items.Add('Pixel Format : pf1bit');
    pf4bit    : ListBox1.Items.Add('Pixel Format : pf4bit');
    pf8bit    : ListBox1.Items.Add('Pixel Format : pf8bit');
    pf15bit   : ListBox1.Items.Add('Pixel Format : pf15bit');
    pf16bit   : ListBox1.Items.Add('Pixel Format : pf16bit');
    pf24bit   : ListBox1.Items.Add('Pixel Format : pf24bit');
    pf32bit   : ListBox1.Items.Add('Pixel Format : pf32bit');
    pfCustom  : ListBox1.Items.Add('Pixel Format : pfCustom');
  end;
  for x := 500 to 600 do
    for y := 500 to 600 do
      begin
        RGB := Image.IEBitmap.Pixels_ie24RGB[x,y];
        ListBox1.Items.Add('RGB : '+CxIn(RGB.r,4)+' '+CxIn(RGB.G,4)+' '+CxIn(RGB.b,2));
      end;
end;





HM Arnold
Go to Top of Page

HMArnold

USA
23 Posts

Posted - Oct 10 2019 :  19:22:52  Show Profile  Reply
It did allow me to attach it as a zip file

Any suggestions appreciated

attach/HMArnold/20191010192127_Sample.zip
1011.54 KB

HM Arnold
Go to Top of Page

xequte

38615 Posts

Posted - Oct 10 2019 :  19:43:16  Show Profile  Reply
Hi

In your code above, you call:

PixelFormat := Image.Bitmap.PixelFormat;

I.e. you are activating the the TBitmap of ImageEnView (setting location to ieTBitmap).

Never use the Bitmap property of TImageEnView (it's for legacy code).

Instead use Image.IEBitmap.PixelFormat:

https://www.imageen.com/help/TIEBitmap.PixelFormat.html



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

HMArnold

USA
23 Posts

Posted - Oct 11 2019 :  11:38:45  Show Profile  Reply
Nigel,

Again, thanks

With everything else taken out, this code fails with the attached floating point error


procedure TForm1.ScanButtonClick(Sender: TObject);
begin
  Image.IO.NativePixelFormat := True; // Use the original pixel format
  Image.IO.LoadFromFileTIFF(ImagePath);
end;





HM Arnold
Go to Top of Page

xequte

38615 Posts

Posted - Oct 11 2019 :  22:39:52  Show Profile  Reply
Hmm, looks like we don't support that type of TIFF after all. We will investigate further...

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

HMArnold

USA
23 Posts

Posted - Oct 12 2019 :  08:47:24  Show Profile  Reply
Thanks

This file format is pretty much the standard for GIS elevation files. The ability to programmatically read and modify these files at the pixel level would have uses in flood and river analysis, agriculture, and environmental applications.

Somehow embedded in the sample file, besides the elevation values, are two other pieces of information, being the spatial datum and a description of how the pixel dimensions relate to the real world.

Recovery of these values would be nice, but not critical.

Its common for this type of file to be included with a "TFW" or "World File", which is a text file that gives all the required numeric values.

Let me know if I can do anything to assist

And thanks again for looking at this

HM Arnold
Go to Top of Page

xequte

38615 Posts

Posted - Oct 15 2019 :  16:45:08  Show Profile  Reply
Hi

We have a fix for this (there are out of range values in this image). Can you supply us some other images for testing?

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

HMArnold

USA
23 Posts

Posted - Oct 31 2019 :  11:32:18  Show Profile  Reply
Sorry for the delay

I've uploaded another from the same area but cut from a different source

Thanks for looking at this


attach/HMArnold/20191031113055_CP66SWV2Small1.zip
3185.46 KB

HM Arnold
Go to Top of Page

xequte

38615 Posts

Posted - Nov 02 2019 :  20:00:21  Show Profile  Reply
Thanks, in next week's release, we'll have a further tweak to improve handling of these kinds of images.

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

HMArnold

USA
23 Posts

Posted - Dec 22 2019 :  09:11:06  Show Profile  Reply
I have now had the chance to install 8.7.5, and it does indeed now load GeoTiffs and allow pixel level access using IEBitmap.

The following code:

  Image.IO.NativePixelFormat := True; // Use the original pixel format
  Image.IO.LoadFromFileTIFF(ImagePath);
  ListBox1.Items.Add('Width  : '+IntToStr(Image.IEBitmap.Width));
  ListBox1.Items.Add('Height : '+IntToStr(Image.IEBitmap.Height));
  PixelFormat := Image.IEBitmap.PixelFormat;

  case PixelFormat of
    ienull   : ListBox1.Items.Add('Invalid pixel format');
    ie1g     : ListBox1.Items.Add('Black/White (1 bit per pixel)');
    ie8p     : ListBox1.Items.Add('RGB color with colormap (256 colors, 8 bit per pixel)');
    ie8g     : ListBox1.Items.Add('Gray scale (256 shades of gray, 8 bit per pixel)');
    ie16g    : ListBox1.Items.Add('Gray scale (65536 shades of gray, 16 bit per pixel)');
    ie24RGB  : ListBox1.Items.Add('RGB true color (16M colors, 24 bit per pixel, 8 bit per channel)');
    ie32f    : ListBox1.Items.Add('Gray scale (0..1 floating point shades of gray, 32 bit per pixel)');
    ieCMYK   : ListBox1.Items.Add('CMYK color (32 bit per pixel, reversed 8 bit per channel)');
    ie48RGB  : ListBox1.Items.Add('RGB color (48 bit per pixel, 16 bit per channel)');
    ieCIELab : ListBox1.Items.Add('CIELab color (24 bit per pixel, 8 bit per channel)');
    ie32RGB  : ListBox1.Items.Add('RGBA color (32 bit per pixel, 8 bit per channel');
  end;
  for x := 50 to 55 do
    for y := 50 to 55 do
      begin
        Pixel := Image.IEBitmap.Pixels_ie32f[x,y];
        ListBox1.Items.Add('Pixel : '+CxReal(Pixel,10,4));
      end;

This code gives valid dimensions, shows the format to be ie32f, and now allows pixel level access using the Pixels_ie3f property.

The values returned are all 1.0000

Attached is a greatly reduced resolution version of a Geotiff, and an image of what this file looks like when loaded into ArcGIS.

attach/HMArnold/20191222967_CP66SWTopo WGS19841 ResampleC.tif



Any help being able to extract the pixel values in a useable form would be greatly appreciated.

I'm expecting values between 17 and 58, representing the height above sea level in feet

Thanks

Hank

HM Arnold
Go to Top of Page

HMArnold

USA
23 Posts

Posted - Dec 29 2019 :  10:28:38  Show Profile  Reply
Any hope of being able to read these values?

HM Arnold
Go to Top of Page

xequte

38615 Posts

Posted - Dec 30 2019 :  14:34:13  Show Profile  Reply
Sorry, I won't be able to check this till after we get back into the office in the new year.

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

xequte

38615 Posts

Posted - Jan 09 2020 :  04:52:23  Show Profile  Reply
Hi

Please email me for an updated version to test. It should be able to handle these kinds of values.

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