Main Content

mergeBlockLocationSets

Merge block location sets

Since R2023a

    Description

    example

    blsMerged = mergeBlockLocationSets(bls1,bims1,bls2,bims2) merges two block location sets, bls1 and bls2. Each block location set selects blocks from the corresponding array of blocked images, bims1 or bims2, respectively.

    [blsMerged,bimsAll] = mergeBlockLocationSets(bls1,bims1,bls2,bims2) also returns the set of all blocked images contributing to the merged block location set.

    Examples

    collapse all

    Create a blocked image.

    bim = blockedImage("tumor_091R.tif");
    blockSize = [128 128];

    Create a mask at the coarsest level. The mask corresponds to regions of the image that contain tissue.

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

    Display all regions with tissue. Specify a region as having tissue when at least 20% of pixels are true in the stained region, as defined by the mask.

    threshTissue = 0.2;
    figure
    h1 = bigimageshow(bim);
    showmask(h1,bmask,BlockSize=blockSize,InclusionThreshold=threshTissue)
    title("Highlighted Tissue Mask")

    Figure contains an axes object. The axes object with title Highlighted Tissue Mask contains an object of type bigimageshow.

    The tissue regions occupy a large portion of the image. When selecting tissue blocks, reduce the size of the data set by adding a gap between sampled blocks. The returned blockLocationSet object contains 184 tissue blocks.

    undersampleFactor = 1.5;
    bls1 = selectBlockLocations(bim,BlockSize=blockSize,Masks=bmask, ...
        InclusionThreshold=threshTissue,BlockOffsets=blockSize*undersampleFactor)
    bls1 = 
      blockLocationSet with properties:
    
        ImageNumber: [184×1 double]
        BlockOrigin: [184×3 double]
          BlockSize: [128 128 3]
             Levels: 1
    
    

    Display the relatively homogeneous regions. Define a homogeneous region as a region in which at least 90% of pixels are true in the stained region, as defined by the mask.

    threshHomogeneous = 0.9;
    h2 = bigimageshow(bim);
    showmask(h2,bmask,BlockSize=blockSize,InclusionThreshold=threshHomogeneous)
    title("Highlighted " + threshHomogeneous*100 + "% Uniform Regions")

    Figure contains an axes object. The axes object with title Highlighted 90% Uniform Regions contains an object of type bigimageshow.

    The homogeneous regions occupy a much smaller portion of the image. To select a balanced number of blocks, oversample the homogeneous blocks. The returned blockLocationSet object contains 166 homogeneous blocks.

    oversampleFactor = 2;
    bls2 = selectBlockLocations(bim,BlockSize=blockSize,Levels=1,Masks=bmask, ...
        InclusionThreshold=threshHomogeneous,BlockOffsets=blockSize/oversampleFactor)
    bls2 = 
      blockLocationSet with properties:
    
        ImageNumber: [166×1 double]
        BlockOrigin: [166×3 double]
          BlockSize: [128 128 3]
             Levels: 1
    
    

    Merge the two sets of blocks.

    blsMerged = mergeBlockLocationSets(bls1,bim,bls2,bim);

    Create a blocked image datastore from the merged set of blocks.

    bimds = blockedImageDatastore(bim,BlockLocationSet=blsMerged);

    Input Arguments

    collapse all

    First set of block locations, specified as a blockLocationSet object.

    First set of blocked images, specified as a blockedImage object or an array of blockedImage objects. These images correspond to the images sampled by bls1.

    Second set of block locations, specified as a blockLocationSet object.

    Second set of blocked images, specified as a blockedImage object or an array of blockedImage objects. These images correspond to the images sampled by bls2

    Output Arguments

    collapse all

    Merged set of block locations, returned as a blockLocationSet object.

    All blocked images, returned as an array of blockedImage objects. If bims1 and bims2 are identical, then bimsAll is also identical to bims1 and bims2. Otherwise, bimsAll is equal to [bims1 bims2].

    Version History

    Introduced in R2023a