Skip to main content

How to find the tile inside a TiledImage to read a ROI?

Please note these java.net forums are being decommissioned and use the new and improved forums at https://community.oracle.com/community/java.
1 reply [Last post]
haerta
Offline
Joined: 2011-06-04

Hi all!

First of all I'd like to write down what I think I understand about JAI and the image coordinate systems and my current task.
I try to read very large (width * height > Integer.MAX_VALUE) images with JAI. Because of memory limitations it is impossible to read them fully into RAM. But luckily all these images I want to read are tiled (ImageReader.isImageTiled = true). My understandin is that it is possible to read only one tile of an image without having to read the whole image into RAM.

At a first step I want to create a list of all tiles that cover the image contents and what "absolute" pixel coordinates (Upper left corner of the image = 0,0) are contained in a particular tile.

I think I understood all facts covered by this URL: http://java.sun.com/products/java-media/jai/forDevelopers/jaifaq.html#co...

My conclusion is that all methods provided by the ImageReader that are related to the tile grid (ImageReader.getTileGridX/YOffset , ImageReader.getTileWidth/Height) return information about the grid layout but no information can be obtained from the ImageReader that says something about the "absolute" position of a pixel coordinate in relation to the tile grid.

So I can get information about the tile 0,0 and therefore can derive the image coordinate of the upper left corner of that tile within the image coordinate system. But I can't find out where that origin in pixel coordinates is and therefore I still don't know what tile to read if I want to read a particular area of interest given in pixel coordinates (Let's say a quadratic roi in the upper left corner of my image given by the upper left corner 0,0 and width of 100 pixels and height of 100 pixels).

What I need seems to be an instance of the ImageLayout class. Its methods getMinX/Y return the "relative" coordinates within the image coordinates. These values can be used to determine the position of the tile 0,0 in reference to the absolute upper left pixel coordinate 0,0. So for example if the TileGridX/YOffsets are 200,400 and minX/Y return -200, 300 I know that the upper left corner of tile 0,0 is 400 pixels to the right and 100 pixels to the bottom of the upper left pixel coordinate of the image.

So far my understanding of the image layout.

Now what I don't understand: It seems that an instance of ImageLayout can only be obtained from a RenderedImage. So it seems that I need to read the whole image to get information about the absolute position of the tilegrid that overlays the image. But as I said before I can't read the whole image due to memory limitations.

So my final question is: How can I find out what tile I have to read if I am interested to read a roi given in pixel coordinates without having to read the whole image?

Thank you very much for any clarification or proof of my misunderstanding.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
rgd
Offline
Joined: 2005-08-23

Hey...

Creating a RenderedImage does *not* read the entire image! The entire
point of it - with a well-written reader than understands tiles - is to
read just the areas you care about. It only needs to read the header to
get the coordinate info you refer to.

So don't be afraid of creating an RI and using it to get the coordinate
origin. It's a relatively lightweight object.

For that matter, what I think you're trying to do is exactly what RI
does for you. If you request a certain area, it should read just those
tiles that are necessary to give you that area. Go ahead and get the RI
from the ImageReader, and request from it the section you care about.
Let the reader and the RI mechanism figure out which tiles to load. It
should Just Work ("should" ;-) ). If you request an area that covers
multiple tiles, depending on how you make the call it might "cobble"
those tiles together, meaning reading them and presenting one unified
buffer for the whole area... but that probably saves a step you would
have to do anyway. Or, make tile-aligned requests to just get tiles.

Hope that helps...

-Bob

On 9/7/11 3:29 PM, forums@java.net wrote:
> Hi all!
> First of all I'd like to write down what I think I understand about JAI and
> the image coordinate systems and my current task.
> I try to read very large (width * height > Integer.MAX_VALUE) images with
> JAI. Because of memory limitations it is impossible to read them fully into
> RAM. But luckily all these images I want to read are tiled
> (ImageReader.isImageTiled = true). My understandin is that it is
> possible to
> read only one tile of an image without having to read the whole image into
> RAM.
> At a first step I want to create a list of all tiles that cover the image
> contents and what "absolute" pixel coordinates (Upper left corner of the
> image = 0,0) are contained in a particular tile.
> I think I understood all facts covered by this URL:
> http://java.sun.com/products/java-media/jai/forDevelopers/jaifaq.html#co...
>
> My conclusion is that all methods provided by the ImageReader that are
> related to the tile grid (ImageReader.getTileGridX/YOffset ,
> ImageReader.getTileWidth/Height) return information about the grid
> layout but
> no information can be obtained from the ImageReader that says something
> about
> the "absolute" position of a pixel coordinate in relation to the tile grid.
> So I can get information about the tile 0,0 and therefore can derive the
> image coordinate of the upper left corner of that tile within the image
> coordinate system. But I can't find out where that origin in pixel
> coordinates is and therefore I still don't know what tile to read if I want
> to read a particular area of interest given in pixel coordinates (Let's
> say a
> quadratic roi in the upper left corner of my image given by the upper left
> corner 0,0 and width of 100 pixels and height of 100 pixels).
> What I need seems to be an instance of the ImageLayout class. Its methods
> getMinX/Y return the "relative" coordinates within the image coordinates.
> These values can be used to determine the position of the tile 0,0 in
> reference to the absolute upper left pixel coordinate 0,0. So for
> example if
> the TileGridX/YOffsets are 200,400 and minX/Y return -200, 300 I know that
> the upper left corner of tile 0,0 is 400 pixels to the right and 100 pixels
> to the bottom of the upper left pixel coordinate of the image.
> So far my understanding of the image layout.
> Now what I don't understand: It seems that an instance of ImageLayout can
> only be obtained from a RenderedImage. So it seems that I need to read the
> whole image to get information about the absolute position of the tilegrid
> that overlays the image. But as I said before I can't read the whole image
> due to memory limitations.
> So my final question is: How can I find out what tile I have to read if
> I am
> interested to read a roi given in pixel coordinates without having to read
> the whole image?
> Thank you very much for any clarification or proof of my misunderstanding.
>
>