how can I convert 2d images to a 3d image?
21 次查看(过去 30 天)
显示 更早的评论
I have a CT scan file with 51 slices...how can I make a 3d image with this 51 slices?
Is there any toolbox in matlab for this?
I attached this file.
7 个评论
Salaheddin Hosseinzadeh
2014-9-14
Hi Sara,
There is no file attached!
There are imbedded functions in Matlab for CT files,but I'm afraid I don't know those functions.
I need to perform 3D reconstruction, except I don't have CT files, slices are produced in a different fashion.
sara
2014-9-15
hi Salaheddin Excuse me ... I was so tired when I wrote answer for you ..yes you are right There is no file attached... now I want to attach this but because the size of this file is bigger than 5 mb, I upload it in 4 file... thanks
采纳的回答
Image Analyst
2014-9-14
You can use cat()
image3d = cat(3, slice1, slice2, slice3, slice4);
or in a loop where you read in each slice
array3d = zeros(rows, columns, numberOfSlices);
for slice = 1 : numberOfSlices
filename = spritnf('image #%d', slice);
fullFileName = fullfile(folder, filename);
if exist(fullFileName, 'file)
thisSlice = imread(fullFileName);
array3d(:,:,slice) = thisSlice;
end
end
or if you don't know the number of slices in advance,
thisSlice = imread(filename);
if slice == 1
array3d = thisSlice
else
array3d = cat(3, array3d, thisSlice);
end
24 个评论
Salaheddin Hosseinzadeh
2014-9-14
Hi Image Analyst,
I have some sort of a similar problem, except that I don't really have CT images, I've something that represents slices from different angles. I'm supposed to do a 3D reconstruction on 2D figures, and produce a 3D one.
I contacted you before, asking for help and provided some further info.
I'll appreciate if you roughly explain what to search for, in MATLAB.
Many thanks,
Salah
Image Analyst
2014-9-14
Well essentially that's what CT is - building up a 3D volumetric image from projections at different angles. I took a semester class in graduate school on 3D reconstruction of MRI and CT from projections. The math is pretty challenging - radon transforms and filtered back projection, etc. The guys who discovered it actually won a Nobel Prize in Medicine for it in 1979. Usually though it's not something you need to know the details of because the CT instrument does the reconstruction for you. If you want to try it yourself in MATLAB you'll need the radon() function and need to study up on the math. The more slices you have the better the reconstruction. Here's a tutorial: http://wn.com/filtered_back_projection and another one
Salaheddin Hosseinzadeh
2014-9-15
编辑:Salaheddin Hosseinzadeh
2014-9-15
Thanks so much Image Analyst.
I'll have a look at the links, soon I gonna get involve in this and may get back to you gain.
Please don't remove your comment.
Many Regards,
SH
sara
2014-9-18
hi Salaheddin Hosseinzadeh
I think we should do cat() step by step for example use cat() for 4 images and then the result of this will use with 3 slices after this...because if you attention to it you can see the slices that are Respectively have a simple changes...but when you want to do it for 44 slices the angles are changed and result is not good.. I didn't try this and it is just an idea ....
Image Analyst
2014-9-18
I didn't understand what you're trying to say. My understanding is that sara has 2D slice images that are already reconstructed and she merely needs to stack them along one dimension, while Salaheddin has 2D images that are projections of the volume along different angles. Hence, Salaheddin cannot simply stack the images along one dimension to get a complete 3D volume. His images must actually undergo a filtered back projection reconstruction process to build the 3D image from the images taken at different angles (that's essentially how CT works).
Xiaoli
2016-10-19
I have the same problem as Sara. I used the cat function to stack the image. How do I view this stacked image. inshow3D does not work. Also does the cat function acutally create a 3D image (like change the pixel to voxels)? I have several binary images where 0 is solid and 1 is pore(empty space), so I want to combine the images to be able to calculate the volume of the pores.
Walter Roberson
2016-10-19
Xiaoli, you can
implay(array3d)
if you want to view the different slices as if they were different times.
You can also use the vol3d File Exchange contribution to visualize as a volume, but to get that to work you might need to use
vol = permute(array3d, [1 2 4 3]);
vol3d('CData', vol(:,:,[1 1 1],:) )
This converts the N x M x P to N x M x 3 x P
Also does the cat function acutally create a 3D image
Yes, under the assumption that the layers are all aligned properly, which is not always the case.
I want to combine the images to be able to calculate the volume of the pores.
When you do volume or area calculations, you need to be careful, because the different directions are not necessarily to the same scale. The X and Y directions are very likely square pixels (not always), but it is common for the Z direction to have a different spacing than the X and Y. If you are using DICOM files, you can read out the slice thickness; see https://www.mathworks.com/matlabcentral/answers/224190-how-can-i-get-that-the-thikness-of-one-slice-of-a-ct-image-is-measured-at-the-milimeter-level#answer_183101
Xiaoli
2016-10-20
Hey thanks. Apparently this 3D rendering in Matlab is complicated and I am new to matlab. A colleague told me about imageJ, which is an open source software, so I am going to try do it in that software.
Nawal SRHIRI
2019-4-13
编辑:Image Analyst
2019-4-14
I have the same problem (a CT scan file with 255 slices) How can I make a 3d image with these 255 slices?
The 'cat' function doesn't work.
Walter Roberson
2019-4-13
Nawal SRHIRI, what is size() of each of your slices ? Are they each 2 dimensional (grayscale) or are they RGB (and so 3 dimensional) ?
Are all of your slices the exact same size?
Image Analyst
2019-4-14
Nawal SRHIRI, did your fisk file images come from JPG images? If so there is a good change they are RGB images even though they appear as gray scale. Try this code:
% Read in demo image.
grayImage = imread(fullFileName);
% Get the dimensions of the image.
[rows, columns, numberOfColorChannels] = size(grayImage)
if numberOfColorChannels > 1
grayImage = grayImage(:, :, 1);
end
Why did the cat() function did not work? Did it throw an error? If so, tell us ALL THE RED TEXT.
Nawal SRHIRI
2019-4-15
编辑:Nawal SRHIRI
2019-4-15
Walter Roberson, the size () of each slice is 512x512 int16, they are the same size
Nawal SRHIRI
2019-4-15
编辑:Nawal SRHIRI
2019-4-15
using this code :
% Read in demo image.
grayImage = imread(fullFileName);
% Get the dimensions of the image.
[rows, columns, numberOfColorChannels] = size(grayImage)
if numberOfColorChannels > 1
grayImage = grayImage(:, :, 1);
end
I have the following error:
Error using imread (line 347)
Cannot open file "C:\Users\User\Desktop\PFE\pro" for reading. You might not have read permission.
then i try this cod:
image_folder ='C:\Users\User\Desktop\PFE\base de données\DICOM\PA0\ST0\SE5';
filenames = dir(fullfile(image_folder, '*.jpg'));
% Get the dimensions of the image.
[rows, columns, numberOfColorChannels] = size(filenames)
if numberOfColorChannels > 1
grayImage = grayImage(:, :, 1);
end
>> cat(3,1,2,3,4,5,6,7,8,9);
but I can not build a 3d image
using this:
>> cat(3,1.jpg,2.jpg,3.jpg,4.jpg,5.jpg,6.jpg,7.jpg,8.jpg,9.jpg);
cat(3,1.jpg,2.jpg,3.jpg,4.jpg,5.jpg,6.jpg,7.jpg,8.jpg,9.jpg);
I have this :
|
Error: Unexpected MATLAB expression.
Did you mean:
>> cat(3,1.j*pcg,2.j*pcg,3.j*pcg,4.j*pcg,5.j*pcg,6.j*pcg,7.j*pcg,8.j*pcg,9.j*pcg);
Error using pcg (line 60)
Not enough input arguments.
Walter Roberson
2019-4-15
image_folder ='C:\Users\User\Desktop\PFE\base de données\DICOM\PA0\ST0\SE5';
dinfo = dir(fullfile(image_folder, '*.jpg'));
filenames = fullfile(image_folder, {dinfo.name});
num_image = length(filenames);
all_images = [];
for K = 1 : num_image
this_image = imread(filenames{K});
if ndims(this_image) > 2
this_image = this_image(:,:,1);
end
if K == 1
[rows, columns] = size(this_image);
all_images = zeros(rows, colums, num_image);
end
all_images(:,:,K) = this_image;
end
Image Analyst
2019-4-15
You can't put wildcards into cat(). Even if you didn't have the *, you still forgot to enclose the strings in single quotes. Just try the code by Walter.
Nawal SRHIRI
2019-4-16
Walter Roberson, i try the code but i have the following error
Error using imread (line 362)
Unable to determine the file format.
Walter Roberson
2019-4-16
I notice that your directory name talks about Dicom. Are you trying to read dicom files this way?
Patil Ravindra kyung hee university
2021-9-8
hello, i am trying to create a 3D image from 12 images which I take in different angle, e.g. 1 image at 30 degree ,2nd image at 60 degree... i tried cat function to create a volume but it is not making 3D images. it just staging my images like slices but my images are in diffrent angle. Can anyone please help me to make 3D volume from my 12 images. my code is below please check and help me please.
a=imread('D:\im\New folder\1.jpg');
b=imread('D:\im\New folder\2.jpg');
c=imread('D:\im\New folder\3.jpg');
d=imread('D:\im\New folder\4.jpg');
e=imread('D:\im\New folder\5.jpg');
f=imread('D:\im\New folder\6.jpg');
g=imread('D:\im\New folder\7.jpg');
h=imread('D:\im\New folder\8.jpg');
i=imread('D:\im\New folder\9.jpg');
j=imread('D:\im\New folder\10.jpg');
k=imread('D:\im\New folder\11.jpg');
l=imread('D:\im\New folder\12.jpg');
img= cat(3,a,b,c,d,e,f,g,h,i,j,k,l);
% vol3d('CData', squeeze(img),'xdata', [0 128], 'ydata', [0 128], 'zdata', [0 128])
vol3d('cdata', squeeze(img), 'xdata', [0 1], 'ydata', [0 1], 'zdata', [0 1]);
can anyone please help me in this code?
Image Analyst
2021-9-8
@Patil Ravindra kyung hee university, you might have to rotate each image before passing it into cat().
Image Analyst
2021-9-8
rotatedImage = imrotate(inputImage, 30, 'bbox', 'crop'); % Rotate by 30 degrees.
Patil Ravindra kyung hee university
2021-9-9
编辑:Walter Roberson
2022-1-24
thank you for reply sir,
i tried imrotate fuction as you said but it showing some error. please check it and tell me corrections.
"
a=imread('D:\im\New folder\1.jpg');
a=imresize(a,[128 128]);
a = imrotate(a, 30, 'bbox', 'crop'); % Rotate by 30 degrees.
b=imread('D:\im\New folder\2.jpg');
b=imresize(b,[128 128]);
b = imrotate(b, 60, 'bbox', 'crop'); % Rotate by 30 degrees.
c=imread('D:\im\New folder\3.jpg');
c=imresize(c,[128 128]);
c = imrotate(c, 90, 'bbox', 'crop'); % Rotate by 30 degrees.
d=imread('D:\im\New folder\4.jpg');
d=imresize(d,[128 128]);
d = imrotate(d, 120, 'bbox', 'crop'); % Rotate by 30 degrees.
e=imread('D:\im\New folder\5.jpg');
e=imresize(e,[128 128]);
e = imrotate(e, 150, 'bbox', 'crop'); % Rotate by 30 degrees.
f=imread('D:\im\New folder\6.jpg');
f=imresize(f,[128 128]);
f = imrotate(f, 180, 'bbox', 'crop'); % Rotate by 30 degrees.
g=imread('D:\im\New folder\7.jpg');
g=imresize(g,[128 128]);
g = imrotate(g, 210, 'bbox', 'crop'); % Rotate by 30 degrees.
h=imread('D:\im\New folder\8.jpg');
h=imresize(h,[128 128]);
h = imrotate(h, 240, 'bbox', 'crop'); % Rotate by 30 degrees.
i=imread('D:\im\New folder\9.jpg');
i=imresize(i,[128 128]);
i = imrotate(i, 270, 'bbox', 'crop'); % Rotate by 30 degrees.
j=imread('D:\im\New folder\10.jpg');
j=imresize(j,[128 128]);
j = imrotate(j, 300, 'bbox', 'crop'); % Rotate by 30 degrees.
k=imread('D:\im\New folder\11.jpg');
k=imresize(k,[128 128]);
k = imrotate(k, 330, 'bbox', 'crop'); % Rotate by 30 degrees.
l=imread('D:\im\New folder\12.jpg');
l=imresize(l,[128 128]);
l = imrotate(l, 360, 'bbox', 'crop'); % Rotate by 30 degrees.
im = cat(3,a,b,c,d,e,f,g,h,i,j,k,l);
vol3d('cdata', squeeze(im), 'xdata', [0 1], 'ydata', [0 1], 'zdata', [0 1]);
"
this is code and the error is :-
"
>> vol3d
Error using imrotate>checkStringValidity (line 312)
Unknown interpolation method or BBOX: bbox
Error in imrotate>parse_inputs (line 277)
checkStringValidity(idx1,arg1);
Error in imrotate (line 69)
[A,ang,method,bbox,catConverter,isInputCategorical] = parse_inputs(args{:});
Error in vol3d>demo_vol3d (line 226)
a = imrotate(a, 30, 'bbox', 'crop'); % Rotate by 30 degrees.
Error in vol3d (line 74)
demo_vol3d;
>>
"
thank you for help.
Patil Ravindra kyung hee university
2021-9-9
thank you for help,i tried 'nearest ' the error is solve but it still staging all images.
it just rotate iamge but all images are stagging on each other.
my images are like a tomography images. in tomography we take images in diffrent angle and combine them to create 3D volume. like shown in below video.
"https://youtu.be/1gottjkU6Jc"
again thank you for help these are great help to me in my work.
Image Analyst
2021-9-9
编辑:Walter Roberson
2022-1-24
Patil, if you've studied medical reconstruction you know a reconstructed image is not merely the sum of rotates images. You have to extrude or "back project" the images before you add them. You are not doing that part so you will not get a reconstruction. Sorry, but writing a 3-D reconstruction algorithm is way beyond what I can offer you. There are people who's whole full time job is working on those kinds of algorithms.
更多回答(1 个)
Rekha Nair
2015-10-14
how can i create a 3d image by using one Plane image(X and Y cordinates) and an oblique view of the same image.
4 个评论
Walter Roberson
2015-10-14
Rekha, you cannot do it with that information. See for example the following image, and notice that you cannot tell the true shape of the objects without a third perspective:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/178917/image.jpeg)
Image Analyst
2017-9-19
If there are shadows, you have a chance. See this overview of "shape from shading" http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.74.7754&rep=rep1&type=pdf
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!发生错误
由于页面发生更改,无法完成操作。请重新加载页面以查看其更新后的状态。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
亚太
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)