I have a set of 2D arrays that I have stacked into a 3D array, how do I make the volume segmentation tool interpolate between layers without manually inputting an ROI?
6 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
If you plan on running the code the zipped folder of images, use .tif when it asks you to select what exstension you want to use. The main issue is when I display it in the volume segmentation tool it will only show thin slices of the areas I want and not show any of the connecting parts in between.
I have a hunch that this might be because the variable image3D_cooked is double? I have spent a ton of time on it and cannot figure it out for my life.
clear
clc
close
%%% Directory and Finding File
d = dir ; %Sets directory to current file
fn = {d.name} ;
[indx,~] = listdlg('PromptString',{'Select the file containing the data you wish to process.', "Only one file can be selected at a time.'"},'SelectionMode','single','ListString',fn) ;
FileName = fn(indx);
%%% Choosing Image extention
list = {'.jpeg' , '.tif'} ;
[indx,~] = listdlg('PromptString',{'Select the image type you wish to process.', "Only one type can be selected at a time.'"},'SelectionMode','single','ListString',list);
typ = list(indx) ;
%%% Create Dataset
imds = imageDatastore(FileName,"IncludeSubfolders",0,"FileExtensions",typ,"LabelSource","foldernames") ;
%%% Count Number of Files in Dataset
nFiles = numel(imds.Files);
%%% Preacllocating Logical Array
isKept = false(1,nFiles) ;
%%% Display Dataset
allImages = readall(imds) ;
imout = imtile(allImages,'GridSize',[1 nFiles],'BackgroundColor','white') ;
imshow(imout)
title("Original Data Set")
%%% Which side would you like to remove slices from
list = {'Remove from Left Side' , 'Remove from Right Side', 'Remove from Both Sides',"Don't Remove Any Slices"} ;
[indx,~] = listdlg('PromptString',{'Would you like to removes slices from the dataset?'},'SelectionMode','single','ListString',list);
%%% Defining Conditionals and Applying isKept attribute to kept files
if indx == 1
Lremoved = inputdlg("How many images would you like to remove from the left? ") ;
Lremoved = str2double(Lremoved) ; %%% Need these conditionals to be scalars
Rremoved = 0 ;
for k = 1:nFiles
isKept(k) = (Lremoved < k) ;
end
elseif indx == 2
Lremoved = 0 ;
Rremoved = inputdlg("How many images would you like to remove from the right? ") ;
Rremoved = str2double(Rremoved) ; %%% Need these conditionals to be scalars
for k = 1:nFiles
isKept(k) = (k <= nFiles-Rremoved) ;
end
elseif indx == 3
Lremoved = inputdlg("How many images would you like to remove from the left? ") ;
Lremoved = str2double(Lremoved) ; %%% Need these conditionals to be scalars
Rremoved = inputdlg("How many images would you like to remove from the right? ") ;
Rremoved = str2double(Rremoved) ; %%% Need these conditionals to be scalars
for k = 1:nFiles
isKept(k) = (Lremoved < k) && (k <= nFiles-Rremoved) ;
end
else
Lremoved = 0 ;
Rremoved = 0 ;
for k = 1:nFiles
isKept(k) = 1 ;
end
end
%%% Display Kept Slices
keptFiles = imds.Files(isKept);
nFilesKept = nnz(isKept); %%% Number of files kept
imout = imtile(keptFiles,'GridSize',[1 nFilesKept],'BackgroundColor','white') ;
close
imshow(imout);
title("Modified Data Set")
%%% Cartesian Cropping and Cylindrical Cropping
A = readimage(imds,Lremoved+1);
[rows, columns] = size(A);
%%% Finding target size to crop images
if rows > columns
targetSize = [columns columns] ;
%%% Finding center of image to center the circle // this will also be
%%% used as the radius for the ROI
if rem(columns,2) == 0
ROI_Center = columns*.5 ;
else
ROI_Center = round(columns*.5)-1; %%%Is default to round up so we must subtract 1
end
else
targetSize = [rows rows] ;
if rem(rows,2) == 0
ROI_Center = rows*.5 ;
else
ROI_Center = round(rows*.5)-1; %%%Is default to round up so we must subtract 1
end
end
crop_rect = centerCropWindow2d([rows,columns],targetSize) ;
%%% Prealocate size of image3D
image3d_cooked = zeros(targetSize(1),targetSize(2),nFilesKept);
A = readimage(imds,Lremoved+1);
%%% Cropping
A = imcrop(A,crop_rect);
imshow(A);
%%% Creating ROI
C_ROI = images.roi.Circle(gca,"Center",[ROI_Center , ROI_Center],"Radius",ROI_Center);
%%% Create Mask from ROI
MASK = createMask(C_ROI) ;
%%% Moves through slices
count = 1 ;
%%% Apply Mask
A = imoverlay(A,~MASK,"black") ;
A = rgb2gray(A) ; %%% Must be put back into grayscale so that the matrices are flattened.
%%%Filtering
A = im2double(A) ;
A = imsharpen(A);
A = imgaussfilt(A);
A = A > 0.85 ;
image3d_cooked(:,:,count) = A;
%%%Placeholder variable
B = A ;
for k = (Lremoved+2):(nFiles-Rremoved)
count = count + 1 ;
A = readimage(imds,k) ;
%%% Crop
A = imcrop(A,crop_rect);
%%% Mask
A = imoverlay(A,~MASK,"black") ;
A = rgb2gray(A) ;
%%%Filtering
A = im2double(A) ;
A = imsharpen(A);
A = imgaussfilt(A);
A = A > 0.85 ;
image3d_cooked(:,:,count) = A;
end
volumeSegmenter(image3d_cooked,'Show3DDisplay',1);
0 Commenti
Risposte (1)
Ranjeet
il 30 Giu 2023
Hi Riley,
The ‘Volume Segmenter’ tool provides functionality of automatic ROI selection on multiple images slices if the ROI on first and the last slice is defined. The following example presents the functionality (you may try automatic/manual interpolation) –
The generated ROI regions along with the original images can be exported to workspace or in a ‘.mat’ file. The ROI regions are exported as masks having 1’s corresponding to ROI in a slice and 0’s elsewhere in a variable named “labels”.
You may find the following resource useful for interpolating between layers of the MRI volume data as it can be represented as gridded data –
You may apply the “labels” (masks) to just have the region corresponding to ROI for every slice (can refer as ‘interpolated_ROI_slices’).
Also, inverting the mask, applying to original images, and then adding the resultant slices to ‘interpolated_ROI_slices’ should provide image slices where 3D interpolation has been applied on ROI regions.
0 Commenti
Vedere anche
Categorie
Scopri di più su 3-D Volumetric Image Processing in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!