Issue with dispaly of 3D images created from multiple 2D slices

조회 수: 9 (최근 30일)
MechenG
MechenG 2025년 1월 22일
댓글: MechenG 2025년 1월 23일
Hi,
I have multiple 2D grayscale image slices (all of them are of same dimensions). I need to stack them to dispaly 3D image. I tried cat function and then implay. But this just plays video, I am not able to see 3D image.
I came across many threads relevant to this. But I am not sure which one will serve the purpose.
I have attached few 2D grayscale slices here. Could someone please suggest the possible method to get 3D reconstruction from these images?

채택된 답변

Anjaneyulu Bairi
Anjaneyulu Bairi 2025년 1월 22일
To effectively stack multiple 2D images and visualize them as a 3D image, follow these steps:
Image Acquisition:
  • Sequentially read each 2D image and store them within a 3D matrix. This matrix acts as a volumetric representation where each slice corresponds to an individual image.
Volume Visualization:
  • Utilize the "volshow" function on the constructed 3D matrix. This function facilitates the rendering and interactive visualization of the volumetric data, allowing for comprehensive analysis and exploration of the 3D image.
  • Alternatively you can use "sliceViewer" for visualization.
Refer the below code for reference:
imageFolder = 'images_dir'; % Specify your image directory
imageFiles = dir(fullfile(imageFolder, '*.png'));
numSlices = length(imageFiles);
% Read the first image to get dimensions
sampleImage = imread(fullfile(imageFolder, imageFiles(1).name));
% Check if the image is RGB and convert to grayscale if necessary
if size(sampleImage, 3) == 3
sampleImage = rgb2gray(sampleImage);
end
[rows, cols] = size(sampleImage);
% Initialize a 3D matrix
volumeData = zeros(rows, cols, numSlices, 'like', sampleImage);
for k = 1:numSlices
imageName = fullfile(imageFolder, imageFiles(k).name);
img = imread(imageName);
% Convert to grayscale if the image is RGB
if size(img, 3) == 3
img = rgb2gray(img);
end
volumeData(:, :, k) = img;
end
% Visualize the 3D volume
volshow(volumeData);
% Using sliceview to visualize
sliceViewer(volumeData);
Output of "volshow" function looks like:
Hope it helps!
  댓글 수: 1
MechenG
MechenG 2025년 1월 23일
Thank you very much!. Actually these are focal stack images. I guess I need to follow different strategy?

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Mathieu NOE
Mathieu NOE 2025년 1월 22일
For a 3D rendering (like MRI) I suggest you try this : vol3d v2 - File Exchange - MATLAB Central
%% create a 3D rendering
out = [];
for k=1:5
img = rgb2gray(imread(['0' num2str(k) '.png']));
out = cat(3,out,img);
end
h = vol3d('cdata',out,'texture','3D');
view(3);
axis tight; daspect([1 1 .4])
alphamap('rampup');
alphamap(.06 .* alphamap);
  댓글 수: 5
MechenG
MechenG 2025년 1월 23일
Thanks! I will look into this.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Lighting, Transparency, and Shading에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by