Steve on Image Processing

August 5th, 2011

Dealing with “Really Big” Images: Viewing

I'd like to welcome guest blogger Brendan Hannigan, a MathWorks developer who worked on improving our set of large-image tools over the course of several releases.

Contents

I want to thank Steve for letting me guest blog about some recent work we did to help our large data users work with their imagery in MATLAB using the Image Processing Toolbox.

Several releases ago, we had been hearing from customers that they had "really big" images that they couldn't work with because they were too large to load into memory. How big are these images? "VERY big", they assured us. They couldn't even LOOK at them, much less operate on them in MATLAB! They could do nothing! They were very frustrated. Well, over the never several releases we worked hard to provide better tools to help these customers out.

Over the next few weeks I'll discuss a series of (relatively) new features that have taken these users from hitting Out of Memory errors at every turn, to being able to visually explore their large imagery in a smooth, interactive tool, to being able to process their images incrementally from disc, all while working with arbitrarily large images of arbitrary file format! A much improved workflow!

For this example we'll be working with a (relatively) large TIFF file that ships with the Mapping Toolbox, boston.tif. This file is only about 37 MB in memory, so not problematic in itself, but the tools I discuss here will scale to any size image.

tiff_filename = 'boston.tif';
imfinfo(tiff_filename)
ans = 

                     Filename: 'C:\MATLABs\R2011a\toolbox\map\mapdemos\boston.tif'
                  FileModDate: '04-Jun-2007 17:12:10'
                     FileSize: 38729900
                       Format: 'tif'
                FormatVersion: []
                        Width: 4481
                       Height: 2881
                     BitDepth: 24
                    ColorType: 'truecolor'
              FormatSignature: [77 77 0 42]
                    ByteOrder: 'big-endian'
               NewSubFileType: 0
                BitsPerSample: [8 8 8]
                  Compression: 'Uncompressed'
    PhotometricInterpretation: 'RGB'
                 StripOffsets: [12x1 double]
              SamplesPerPixel: 3
                 RowsPerStrip: 256
              StripByteCounts: [12x1 double]
                  XResolution: 300
                  YResolution: 300
               ResolutionUnit: 'Inch'
                     Colormap: []
          PlanarConfiguration: 'Chunky'
                    TileWidth: []
                   TileLength: []
                  TileOffsets: []
               TileByteCounts: []
                  Orientation: 1
                    FillOrder: 1
             GrayResponseUnit: 0.0100
               MaxSampleValue: [255 255 255]
               MinSampleValue: [1 1 1]
                 Thresholding: 1
                       Offset: 38729291
             ImageDescription: '"GeoEye"'
                     DateTime: '2007:02:23 21:46:13'
                    Copyright: '"(c) GeoEye"'
           ModelPixelScaleTag: [3x1 double]
             ModelTiepointTag: [6x1 double]
           GeoKeyDirectoryTag: [24x1 double]
            GeoAsciiParamsTag: 'State Plane Zone 2001 NAD = 83|'

"I can't even LOOK AT my image!"

Our first foray into large data viewing was simply producing an "overview" style image. If your image is too large to load into memory then it is not possible to view it using imshow with any of the standard syntaxes. Before committing the time and resources necessary work with a large image (moving it, copying it, converting to a different format, etc) users just want to do a "sanity" check on the data.

To help them accomplish this task we provided (in release R2008a) a very simple option to the imshow function, the 'Reduce' parameter. When set to true, imshow will subsample a large TIFF file and display a reduced version of that image. The subsampling ratio is based on your reported screen resolution.

This parameter is only valid for TIFF images. We started with the TIFF format in the beginning because MATLAB has excellent support for incremental reading and writing of TIFF images using the Tiff class. We recognize that most users will not be working exclusively with TIFF imagery and will want to view files in other formats as well.

Now... I don't want to scoop my subsequent blog posts too much, but let's just say we hope that we have sufficiently "adapted" (<== hint) to these customers' needs.

Let's view a reduced version of our image.

imshow(tiff_filename,'Reduce',true,'InitialMagnification','fit');

You'll notice that if you zoom in using the figure zoom tool that you will not see higher resolution imagery. Here's a closer look at Fenway Park.

% Simulate interactive zoom
xlim([44 390])
ylim([2638 2858])

It's clear here that you are actually viewing a reduced-resolution version of the original image. This 'Reduce' parameter is intended for users who just want to get a "quick & dirty" overview of a large TIFF image, and is not appropriate for seeing details in large images.

"That's cute, but I need to see my ACTUAL image, not some decimated imposter!"

Next we wanted to provide some "real", industrial strength large image viewing tool. To provide the best interactive viewing experience possible, we must create a multiresolution version of large images so that we can pull in pixels from the appropriate zoom-level as you pan and zoom through the data set.

Most users will be familiar with this behavior; it's very similar to how online mapping tools work. As you navigate around online maps, you will see tiles of data at discrete zoom levels (resolutions) being assembled to make up the current map view.

To provide this feature we delivered a new function (in release R2009a), rsetwrite, which allows you to create a reduced resolution data set (R-Set) from a large TIFF or NITF file. Creating the R-Set can take some time depending on the size of the image, but it is a one-time, up front cost.

To create an R-Set, the syntax is very straightforward. Let's build an R-Set from our large boston.tif image.

rset_filename = 'boston.rset';
rsetwrite(tiff_filename,rset_filename);

Now that you have your R-Set file, you can simply view it using the Image Tool as you would any other supported image file:

   imtool(rset_filename)

Here's a screenshot:

Using the Image Tool's pan & zoom tools you can now zoom into Fenway Park and see that, using the R-Set, we are now displaying the full resolution image data.

Here's another screenshot:

With R-Sets, you can zoom and pan around images of ANY SIZE, and the Image Tool will pull in only the data that it needs. Navigation of large imagery has never looked so good!

"Ok yea that's not bad, but I need to do more than just view the data!"

There are still many issues that I have not covered here such as, "I need to do more than just view my images", and "I'm not using TIFF or NITF files, what now?". These are excellent questions that I'll discuss next time. Stay Tuned!


Get the MATLAB code

Published with MATLAB® 7.12

10 Responses to “Dealing with “Really Big” Images: Viewing”

  1. Sid replied on :

    I’ve never used the rsetwrite function, but it has brought up some very interesting implications for some of my work. I was wondering whether using a combination of imtool, rsetwrite and MATLAB Builder for JAVA, it might be possible to deploy a multiscale image viewer over the web using WebFigures ?
    Thanks.

  2. John Marcovici replied on :

    This is great. I always wanted to use imtool but couldn’t because of some issues you touched on and others. Some issues I have:
    (1) I need to specify my own decimation routine when building the rsets. Our stuff looks awful with subsampling so we use specific decimation routines. Can I supply a function handle that will generate the rth tile?
    (2) Can complex-valued data be supported? Perhaps a combination of the above and another function handle for scaling would do it?

  3. Steve replied on :

    John—rsetwrite uses the antialiasing provided by imresize. Is this not performing well enough for you? There isn’t a way right now to override this behavior.

    For complex-valued data, you could consider writing your own ImageAdapter class. Brendan’s going to do another guest blog post soon on that topic.

  4. John Marcovici replied on :

    Thanks Steve, I will look at ImageAdapter for complex-valued data. The antialiasing is probably fine… but we are required to decimate a certain way.

  5. Steve replied on :

    Sid—No, use of imtool is not supported by MATLAB Compiler.

  6. Rick replied on :

    Why not a spooled/tiled implementation a la photoshop?

  7. Steve replied on :

    Rick—I’m not certain exactly which aspect of this post or the comments that your comment refers to. Can you be more specific?

  8. Kiko replied on :

    .

    i posted this on matlabcentral but maybe here is a better place. i love the idea of r-set but how can i used it with a matrix? i have version R2009a and i am pretty sure i don’t have the image processing toolbox even ‘tho i think i can find it on campus . here is my posting…

    i need to diplay a large matrix that is made-up of about 1,500 smaller 640×480 matrices (460,800,000 elements in total). in reality these matrices are thermal infrared photos of a concrete bridge deck.

    the FOV of the thermal IR camera (FLIR ThermaCAM SC640) was so small so we had to do many passes (lanes) to collect pictures of the whole deck. it was a ~200ft long bridge about 24ft wide. we had to do 12 passes collecting 125 photos on each pass.

    this large matrix is a 460,800,000 (7,680×60,000) element matrix that needs to be displayed showing the “now stitched” complete bridge deck.

    processing the matrix itself is a challenge but i am confident that i can find a computer that can do it. now displaying the image is proving to be a little more difficult even with a smaller (only 150 photos, 10%) matrix.

    what’s the best way to do it? what’s the best command?

    can i use scroll bars? am i limited by my screen?

    how can i reduce the photo/matrix for display? any ideas?

    you can get more specifics on the data collection used on page 13 of this document;

    http://mtri.org/bridgecondition/doc/Tech%20Memo%2020%20-%20Field%20Deployment%20and%20Instrument%20Installation%20and%20Calibration%20Plan%20Final.pdf

    general project overview at;

    http://mtri.org/bridgecondition/

    thanks, kiko

  9. Sid replied on :

    Is there any way to use a JPEG2000 image as the input to rsetwrite (other than writing an ImageAdapter class)? I assumed that since the imread function supports JPEG2000, the resetwrite function would be able to use JPEG2000 images as inputs.

  10. Steve replied on :

    Sid—No.


MathWorks
Steve Eddins is a software development manager in the MATLAB and image processing areas at MathWorks. Steve coauthored Digital Image Processing Using MATLAB. He writes here about image processing concepts, algorithm implementations, and MATLAB.

These postings are the author's and don't necessarily represent the opinions of The MathWorks.