How can I have a script automatically zoom onto a region of interest?

4 views (last 30 days)
Hello,
The data to be processed by the script I am writing is in the form of arrays, which are then shown as images. The array elements are all equal to zero except where there is information, and the information will be in a different spot every time. The arrays are quite large, and the elements with info don't take up much space at all, so at the moment when the figure is displayed, there is plenty of blank space.
So, I want the script to automatically zoom onto the information area (the non-zero part of the array), no matter where the information might be in the array.
(feel free to ask for context or more information)
Cheers all!
  1 Comment
Henry Kricancic
Henry Kricancic on 29 Jun 2015
Thank you all for the very fast replies - I will report back tomorrow when I return to work.
Cheers.

Sign in to comment.

Accepted Answer

Image Analyst
Image Analyst on 29 Jun 2015
You can find out locations of non-zero information with the find() function. Then zoom in to one of those locations. Not sure how you want to user to specify the location - perhaps list all the locations in a listbox and they can click on one. See my script for zooming an image (adapted from code the Mathworks wrote for me).
  4 Comments
Image Analyst
Image Analyst on 30 Jun 2015
Like I said, you can use find() to give a list of every non-zero pixel location. If you want to group connected non-zero regions together into a single location defined by it's bounding box, then you can call bwlabel() and then regionprops() to find out the bounding box of that region. Then zoom into that area or crop it out to a second image. See my Image Segmentation tutorial for instructions on how to do that. http://www.mathworks.com/matlabcentral/fileexchange/?term=authorid%3A31862

Sign in to comment.

More Answers (1)

Walter Roberson
Walter Roberson on 29 Jun 2015
Have you considered working with sparse arrays and using find() ?
For regular 2D arrays you would use regionprops() to extract the connected components; that would give you bounding boxes and even allow you to extract a copy of the sub-array in a single call. Taking the bounding box that encloses everything is a minor amount more work once you have the individual bounding boxes, with most of that work being due to the fact that bounding boxes are reported with width and height rather than start and end positions.
  1 Comment
Henry Kricancic
Henry Kricancic on 29 Jun 2015
I'm sorry, I don't quite understand what you mean? I should mention I'm a bit of a beginner here... Those are some interesting points (sparse, regionprops, find) for me to look into though; I'm checking them out now. Cheers.

Sign in to comment.

Categories

Find more on Visual Exploration in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!