Put data in specific block of big image
bigimage. This examples uses a modified version of image "tumor_091.tif" from the CAMELYON16 data set. The original image is a training image of a lymph node containing tumor tissue. The original image has eight resolution levels, and the finest level has resolution 53760-by-61440. The modified image has only three coarse resolution levels. The spatial referencing of the modified image has been adjusted to enforce a consistent aspect ratio and to register features at each level.
bim = bigimage('tumor_091R.tif');
bigimage, then create a circle ROI over the displayed image.
h = bigimageshow(bim); hROI = drawcircle(gca,'Radius',470,'Position',[1477 2284]);
Choose the level at which to create a writeable
bigimage. Level 3 is the coarsest resolution level.
maskLevel = 3;
Get the spatial referencing and pixel extents from the specified level.
ref = bim.SpatialReferencing(maskLevel); pixelExtent = [ref.PixelExtentInWorldX,ref.PixelExtentInWorldY];
Create a writeable
bigimage by specifying the spatial referencing instead of image data. This big image has one channel and data type
bmask = bigimage(ref,1,'logical');
Loop through all blocks in the writeable big image to create a mask image. For each block, set the pixel values as
true) for pixels inside the ROI and
false) for pixels outside the ROI.
for cStart = 1:bmask.BlockSize(2):ref.ImageSize(2) for rStart = 1:bmask.BlockSize(1):ref.ImageSize(1) % Get the center of top left pixel of this block in world units. xyStart = [cStart,rStart].*pixelExtent; % Get the block size. The |'BlockSize'| property represents the % size as a 2-element vector of the form [row,column]. Switch the % order of the elements so that the block size is represented as % [x,y]. bsize = bmask.BlockSize bsize = fliplr(bsize); % Get the center of the bottom right pixel of this block in world % units. xyEnd = ([cStart,rStart] + (bsize-1)).*pixelExtent; % Use the |meshgrid| function to determine the (x,y) coordinates in % world units for all pixels in this block. [xgrid, ygrid] = meshgrid(xyStart(1):pixelExtent(1):xyEnd(1),... xyStart(2):pixelExtent(2):xyEnd(2)); % Determine which pixels have coordinates inside the ROI. roiPositions = hROI.Vertices; blockMask = inpolygon(xgrid,ygrid, ... roiPositions(:,1),roiPositions(:,2)); % Set the pixel values of the block. setBlock(bmask,1,xyStart,blockMask); end end
bsize = 1024 1024
Display the mask.
locationWorld— Coordinate of a point
Coordinate of a point, specified as a 1-by-2 numeric vector of the form
y]. The location is specified in world coordinates, which are the pixel
locations relative to the highest resolution level. The position must be a valid
Create a writeable
bigimage by using a syntax that does not
initialize image data. If you create a
bigimage by specifying the file
name, directory name, or variable name of image data, or by using the
apply function, then the
bigimage is not
writeable and you cannot use the
setBlock trims data for partial edge blocks.