sub2world
Description
Examples
Convert Pixel Subscripts to World Coordinates
Convert pixel subscripts from one level to another via the world coordinates.
Create a blocked image from a sample image included with the toolbox.
bim = blockedImage("tumor_091R.tif");
Create a binary mask at the coarsest resolution level.
bmask = apply(bim, @(bs)imbinarize(im2gray(bs.Data)),Level=3);
Define a region of interest (ROI) in the finest resolution level in pixel subscripts.
pixelStartLevel1 = [1700 1550]; pixelEndLevel1 = [2100 2000]; imagePixelSubs = [pixelStartLevel1; pixelEndLevel1];
Get the image data from the ROI at the finest resolution level.
roiImage = getRegion(bim,pixelStartLevel1,pixelEndLevel1,Level=1); size(roiImage)
ans = 1×3
401 451 3
Convert the pixel subscripts that define the ROI into world coordinates. By default, sub2world
converts the coordinates at the finest resolution level.
worldRegion = sub2world(bim,imagePixelSubs);
Convert the world coordinates of the ROI to pixel subscripts of the mask.
maskPixelSubs = world2sub(bmask,worldRegion);
Get the mask data from the ROI.
roiMask = getRegion(bmask,maskPixelSubs(1,:),maskPixelSubs(2,:)); size(roiMask)
ans = 1×2
51 58
View the region of interest and the corresponding mask.
montage({roiImage,roiMask})
Input Arguments
bim
— Blocked image
blockedImage
object
Blocked image, specified as a blockedImage
object.
pixelsub
— Pixel subscripts
K-by-N integer-valued vector
Pixel subscripts, specified as a K-by-N
integer-valued vector, where K is the number of pixels.
N is equal to or less than the number of dimensions of the blocked
image bim
. For example, you can exclude a color channel from the
conversion by specifying the pixel subscripts with one less dimension than the blocked
image.
L
— Resolution level
1
(default) | positive integer
Resolution level, specified as a positive integer that is less than or equal to the
number of resolution levels of bim
.
Output Arguments
world
— World coordinates
K-by-N numeric matrix
World coordinates, returned as a K-by-N numeric array, where K is the number of pixels and N is the dimensionality of the coordinates.
Version History
Introduced in R2021aR2023a: Support for lower dimensionality pixel subscripts
You can now specify the pixel subscripts in a lower dimensionality than the
dimensionality of the blocked image bim
. The function returns the world
coordinates with the same dimensionality as the pixel subscripts.
See Also
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)