How to delete level(s) from a blockedImage object?

1 visualizzazione (ultimi 30 giorni)
JSC
JSC il 30 Lug 2021
Commentato: Ashish Uthama il 8 Mag 2022
Following the MATLAB guide for spatial referencing using blocked images, I am attempting to analyze a pyramidal 23-level SCN image file. It is a whole-slide image of a microscope slide. The fact that each level has a different aspect ratio (printed from table t) confirms what I already knew, which is that reading the file into MATLAB also pulls extra images for the slide label, macro image, and thumbnail image. bigimageshow() then tries to display these unwanted images, thinking that they are some of the coarse and mid-resolution image levels. You can see this in the output below, where it reads the slide label as the coarsest resolution level.
bim=blockedImage('3_2_3_he.SCN');
bimds=blockedImageDatastore(bim);
% Display the spatial referencing information at the finest level. The
% image size (specified by the |Size| property) matches the extents in
% world coordinates. Notice that the default image coordinate system puts
% the center of the first pixel at (1,1). Because the pixel extents are 1
% unit wide in each dimension, the left edge of the first pixel starts at
% (0.5,0.5).
finestLevel = 1;
finestStart = bim.WorldStart(finestLevel,:)
finestEnd = bim.WorldEnd(finestLevel,:)
%%
% Display the spatial referencing information at the coarsest level.
coarsestLevel = bim.NumLevels;
coarsestStart = bim.WorldStart(coarsestLevel,:)
coarsestEnd = bim.WorldEnd(coarsestLevel,:)
%% Verify Aspect Ratio
% Display the image size and aspect ratio at each level. The aspect ratio
% is not consistent, which indicates that levels do not all span the same
% world area. Therefore, the default assumption is incorrect for this image.
t = table((1:bim.NumLevels)',bim.Size(:,1),bim.Size(:,2), ...
bim.Size(:,1)./bim.Size(:,2), ...
'VariableNames',["Level" "Height" "Width" "Aspect Ratio"]);
disp(t)
%% Display Layers to Compare Spatial Extents
%
% Display the blocked image by using the |bigimageshow| function. Display the
% coarsest resolution level.
figure
subplot(1,2,1);
hl = bigimageshow(bim,'ResolutionLevel',coarsestLevel);
title('Coarsest Resolution Level (23)')
%%
% Display image data at the default resolution level in the same
% figure window. By default, |bigimageshow| selects the level to display
% based on the screen resolution and the size of the displayed region.
subplot(1,2,2);
hr = bigimageshow(bim);
title('Default Resolution Level')
Output:
My question is 1) how do I view or otherwise check which resolutions levels are the ones I need of the slide itself, and 2) how do I discard these levels from the blockedImage object to exclude them from any image processing I do later? I know that I can view levels one at a time with
bigimageshow(bim,'ResolutionLevel',level)
by changing 'level' to be 1 through 23 (or however many levels an image has), but I have hundreds of these images, so finding a way to do this in a script in MATLAB would be ideal, rather than doing them by hand one at a time. I want to remove these extra levels/images before I perform registration and segmentation.

Risposte (1)

Ashish Uthama
Ashish Uthama il 6 Mag 2022
I couldnt easily find info about the .SCN format, but since it looks like the default construction syntax works - I assume its some kind of TIFF file? If so, there might be something in the IMFINFO output that tells the specimen image apart from the others. If you have a sample file you can share somewhere - I/someone could take a quick look to see if there is some other meta data to programmatically determine which levels are required.
Once you have that, it might be best to create a one-time copy of the data using write() picking only the levels you need. This will remove the unwanted data, reduce total size and also give you the oppourtunity to control the file blocking to better suite your application (and also potentially add loss-less/lossy compression if required).
Another way would be to write a custom adapter, deriving from say the existing TIFF adapter to explicitly filter out these levels.
  2 Commenti
JSC
JSC il 6 Mag 2022
Thanks for your reply. I ended up converting them to .SVS files using Aperio Imagescope, which is meant for viewing .SCN files. After some serious downscaling, I was able to process the SVSs in MATLAB without loading them as blockedImage objects at all, and then I upscaled my masks again for use on the originals.
I'll keep your advice in mind in case we need to do something like this again.
Ashish Uthama
Ashish Uthama il 8 Mag 2022
Glad you are unstuck.
If you need to do it again, depending on the amount of details in your mask - you could do something like this example (i.e use a downsample mask on a full resolution level).

Accedi per commentare.

Prodotti


Release

R2021a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by