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

조회 수: 1 (최근 30일)
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
Henry Kricancic
Henry Kricancic 2015년 6월 29일
Thank you all for the very fast replies - I will report back tomorrow when I return to work.
Cheers.

댓글을 달려면 로그인하십시오.

채택된 답변

Image Analyst
Image Analyst 2015년 6월 29일
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
Image Analyst
Image Analyst 2015년 6월 30일
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
Henry Kricancic
Henry Kricancic 2015년 6월 30일
Wow, okay thank you for the help!

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Walter Roberson
Walter Roberson 2015년 6월 29일
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
Henry Kricancic
Henry Kricancic 2015년 6월 29일
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.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Data Exploration에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by