Main Content

selectBlockLocations

Select blocks from blocked images

Description

blset= selectBlockLocations(智能化系统)selects a set of nonoverlapping unique blocks from one or moreblockedImageobjects智能化系统at the finest resolution available in each image. Returnsblset, ablockLocationsSetobject.

example

blset= selectBlockLocations(智能化系统,Name,Value)specifies additional options about the blocks to select, such as the overlap and spacing between blocks, using one or more name-value pair arguments.

Examples

collapse all

Create a blocked image.

bim = blockedImage('tumor_091R.tif');

Create a block location set excluding incomplete blocks.

bls = selectBlockLocations(bim,'ExcludeIncompleteBlocks',true);

Create ablockedImageDatastorefrom this set of blocks.

bimds = blockedImageDatastore(bim,'BlockLocationSet', bls);

Visualize the blocked locations.

bigimageshow(bim)

Block size is in row-col (height-width) order.

blockedWH = fliplr(bls.BlockSize(1,1:2));forind = 1:size(bls.BlockOrigin,1)% BlockOrigin is already in x,y order.drawrectangle('Position', [bls.BlockOrigin(ind,1:2),blockedWH]);end

图包含一个axes object. The axes object contains 21 objects of type bigimageshow, images.roi.rectangle.

Create a blocked image.

bim = blockedImage('tumor_091R.tif');

Create ablockLocationSetobject.

blockSize = [2048 3072]; overlapPct = 0.5; blockOffsets = round(blockSize.*overlapPct); bls = selectBlockLocations(bim,...'BlockSize', blockSize,...'BlockOffSets', blockOffsets,...'ExcludeIncompleteBlocks', true);

Create ablockedImageDatastorefrom this set of blocks.

bimds = blockedImageDatastore(bim,'BlockLocationSet', bls);

Visualize the blocked locations.

bigimageshow(bim)

Block size is in row-col (height-width) order.

blockedWH = fliplr(bls.BlockSize(1,1:2)); colors = prism(size(bls.BlockOrigin,1));forind = 1:size(bls.BlockOrigin,1) blockedColor = colors(ind,:);% BlockOrigin is already in x-y orderdrawrectangle('Position', [bls.BlockOrigin(ind,1:2), blockedWH],'Color', blockedColor);end

图包含一个axes object. The axes object contains 7 objects of type bigimageshow, images.roi.rectangle.

Create a blocked image.

bim = blockedImage('tumor_091R.tif');

Create ablockLocationSetobject.

blockedSize = [1024 512]; spacePct = 0.5; blockedOffsets = blockedSize + blockedSize.*spacePct; bls = selectBlockLocations(bim,...'BlockSize', blockedSize,...'BlockOffSets', blockedOffsets,...'ExcludeIncompleteBlocks', true);

Create ablockedImageDatastoreobject from this set of blocks.

bimds = blockedImageDatastore(bim,'BlockLocationSet', bls);

Visualize the block locations.

bigimageshow(bim)% Block size is in row-col (height-width) orderblockedWH = fliplr(bls.BlockSize(1,1:2));forind = 1:size(bls.BlockOrigin,1)% BlockOrigin is already in x-y orderdrawrectangle('Position', [bls.BlockOrigin(ind,1:2), blockedWH]);end

图包含一个axes object. The axes object contains 22 objects of type bigimageshow, images.roi.rectangle.

Create a blocked image.

bim = blockedImage("tumor_091R.tif");

Display the blocked image.

h = bigimageshow(bim);

图包含一个axes object. The axes object contains an object of type bigimageshow.

Create a mask at the coarsest level.

clevel = bim.NumLevels; bmask = apply(bim,@(b)~imbinarize(im2gray(b.Data)),"Level",clevel);

UseshowMaskto estimate anInclusionThresholdvalue.

showmask(h,bmask,"BlockSize",[256 256],"InclusionThreshold",0.9)

图包含一个axes object. The axes object contains an object of type bigimageshow.

Create ablockedImagedatastorefor blocks in which at least 90% of pixels aretruein the stained region as defined by the mask.

mbls = selectBlockLocations(bim,..."Levels",1,..."Masks",bmask,"InclusionThreshold",0.90,..."BlockSize",[256 256]);

Create ablockedImageDatastorefrom this set of blocks.

bimds = blockedImageDatastore(bim,"BlockLocationSet",mbls);

Verify.

bimds.ReadSize = 10; blocks = read(bimds); figure montage(blocks,"BorderSize",5,"BackgroundColor","b");

图包含一个axes object. The axes object contains an object of type image.

Input Arguments

collapse all

Blocked images, specified as ablockedImageobject orb-element vector ofblockedImageobjects.

Name-Value Arguments

Specify optional pairs of arguments asName1=Value1,...,NameN=ValueN, whereNameis the argument name andValueis the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

Before R2021a, use commas to separate each name and value, and encloseNamein quotes.

Example:'BlockSize',[224 224]sets the block size to 224-by-224.

Offset of adjacent blocks, specified as a 2-element row vector of positive integers of the form [rowscolumns].

The default value is equal toBlockSize, resulting in non-overlapping blocks. To overlap blocks, specify a smaller value. To add a gap between blocks, specify a larger value.

Block size, specified as a 2-element row vector of positive integers of the form [rowscolumns]. The default value is equal to theBlockSizeproperty at the finest resolution level of the first blocked image in智能化系统.

Exclude incomplete blocks that are smaller than 'BlockSize', specified asa numeric or logical0(false) or1(true).

Inclusion threshold for mask blocks, specified as a numeric scalar or ab-element numeric vector with values in the range [0, 1]. TheInclusionThresholdargument must have the same number of elements as theMasksargument. TheselectBlockLocationsfunction selects blocks that overlap the foreground of the corresponding mask block by a percentage greater than or equal to the value specified by'InclusionThreshold'.

  • When the inclusion threshold is0,selectBlockLocationsfunction selects a block when at least one pixel in the corresponding mask block is nonzero.

  • When the inclusion threshold is1,selectBlockLocationsfunction selects a block only when all pixels in the mask block are nonzero.

Resolution level of blocks from each blocked image in智能化系统, specified as a scalar positive integer or an array of the same size as智能化系统. If you specify a scalar value, theselectBlockLocationsfunction selects blocks from all blocked images at the same resolution level. Default value is the finest level of each image in the array of blocked images,智能化系统.

Data Types:double

Mask images, specified as an array the same size as智能化系统. The underlying data type of the mask images islogical. TheselectBlockLocationsfunction selects blocks that overlap the foreground of the corresponding mask block by an amount specified byInclusionThreshold. Masks are expected to be in the same world coordinate system as the correspondingblockedImagein the智能化系统array.

Use parallel processing to evaluate mask blocks, specified asa numeric or logical0(false) or1(true). Parallel evaluation of masks is beneficial when the masks do not fit in memory.

Use of parallel processing requires Parallel Computing Toolbox™. TheselectBlockLocationsfunction uses an existing parallel pool of workers, or opens a new pool when no parallel pool is active. TheSourceproperty of each blocked image in智能化系统must be a valid path on all of the parallel workers.

Output Arguments

collapse all

Block locations, returned as ablockLocationSetobject.

References

[1]Bejnordi, Babak Ehteshami, Mitko Veta, Paul Johannes van Diest, Bram van Ginneken, Nico Karssemeijer, Geert Litjens, Jeroen A. W. M. van der Laak, et al. “Diagnostic Assessment of Deep Learning Algorithms for Detection of Lymph Node Metastases in Women With Breast Cancer.” JAMA 318, no. 22 (December 12, 2017): 2199–2210. https://doi.org/10.1001/jama.2017.14585.

Version History

Introduced in R2020b