How can I have a script automatically zoom onto a region of interest?
7 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Henry Kricancic
am 29 Jun. 2015
Kommentiert: Henry Kricancic
am 30 Jun. 2015
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!
Akzeptierte Antwort
Image Analyst
am 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 Kommentare
Image Analyst
am 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
Weitere Antworten (1)
Walter Roberson
am 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.
Siehe auch
Kategorien
Mehr zu Visual Exploration finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!