How can I obtain voxel coordinates and corresponding intensity value of all voxels in a MRI image?
15 次查看(过去 30 天)
显示 更早的评论
Hi I have medical MRI images. I wish to obtain all voxel coordinates as 3 columns with the 4th column giving the corresponding intensity value.
1st column :- X coordinate
2nd column :- Y coordinate
3rd column :- Z coordinate
4th column :- corresponding intensity value
Is there any function that can automatically do that ? The file format is DICOM file. Your help is appreciated
回答(1 个)
Image Analyst
2015-12-11
Yes, use meshgrid and (:). Something like (untested)
[x, y, z] = meshgrid(1:columns, 1:rows, 1:slices);
out4Column = [x,y,z, yourImage(:)];
15 个评论
Sara Salimi
2015-12-11
编辑:Sara Salimi
2015-12-11
Dear Image Analyst, Thanks for your answer. I'm a beginner in matlab. How can I load MRI image and how can apply this command for that image Voxels? I know we can load the image by dicomread() command. But I don know how can I apply those command to find the position and intensity of voxels? I need to extract coordinates and intensity for each voxel. I have attached one of the files. Could you please help me? Once again Thanks a lot for your help.
Walter Roberson
2015-12-11
out4Column = [x,y,z, yourImage(:)]; should be
out4Column = [x(:), y(:), z(:), yourImage(:)];
Walter Roberson
2015-12-11
Once you have your 4D array, say X, then you can get the results you are looking for by:
idx = find(X);
[row, col, page] = ind2sub(size(X), idx);
out4Column = [col(:), row(:), page(:), X(idx)];
Notice that I used col and then row rather than row and then col. In MATLAB, the rows correspond to Y (height) and the columns correspond to X (across)
The above lists only the non-zero values. If you want to include the 0 values as well, that can be done without much trouble.
The coordinates that would be used here are pixel coordinates. If you need the values in real-world coordinates, it will be necessary to extract some header information from the dicom files to figure out how pixels corresponds to x and y and z.
Sara Salimi
2015-12-13
Dear Walter, many thanks for your answer, I tried the code for a folder of MRI images and it was successful. It gave me out4Column with 4 columns. Could you please explain what is idx = find(X)? Is X(idx) the amount of intensity for the voxel? Is the first column as col number and second column as row number? Nevertheless I appreciate your help.
Thanks
Walter Roberson
2015-12-13
"k = find(X) returns a vector containing the linear indices of each nonzero element in array X."
I did code the first column of the output as column number (which corresponds to X), then the second as row number (which corresponds to Y), then the third as page number (which corresponds to Z), then the fourth as the intensity.
It is not common to create a table of values such as this: most of the time that you need this kind of information, it is easier to deal with it as separate variables then as a single matrix. Mostly a table like this is useful for writing the values out to a file.
Keep in mind that the size of the table might be up to 4 times larger than the size of the image array itself, if none of the values in the image are 0.
Sara Salimi
2015-12-13
Dear Walter, Once again Thanks alot for your help.
I really appreciate it.
Regards
Sara
Sara Salimi
2015-12-15
Hi again,
I changed the code for another folder which includes 22 dicom image; however, it gives this error "Subscripted assignment dimension mismatch.
Error in TempTest (line 10) X(:,:,1,p) = dicomread(filename); "
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/180815/image.png)
I also changed the image array size to 22 (number of images in the folder). Before I change the folder, it was working for dicom image downloaded from Dicom example files ,what is the problem? :(
Thanks for your help in advance
Walter Roberson
2015-12-15
Some of your images are a different size. You should assign the result of dicomread() to a variable and then test the size() of the result to determine whether it fits into the array. See my code in http://uk.mathworks.com/matlabcentral/answers/258988-loading-mutiple-dicom-images#answer_202284
Sara Salimi
2015-12-17
Hi Walter, I checked the size of files, you are absolutely right, It shows which of my images is corrupt. For the next step, what should I solve this issue and resize all dicom files with a same size?
I really appreciate your help :)
Image Analyst
2015-12-17
Contact the manufacturer or person that made your images to find out why they're different sizes.
Vasantha Lakshmi
2017-3-9
I need to get the voxel coordinates and intensity values of mri image which are of .mha format.How can I get it?
另请参阅
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 (한국어)