You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
How can I obtain voxel coordinates and corresponding intensity value of all voxels in a MRI image?
13 views (last 30 days)
Show older comments
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
Answers (1)
Image Analyst
on 11 Dec 2015
Yes, use meshgrid and (:). Something like (untested)
[x, y, z] = meshgrid(1:columns, 1:rows, 1:slices);
out4Column = [x,y,z, yourImage(:)];
15 Comments
Sara Salimi
on 11 Dec 2015
Edited: Sara Salimi
on 11 Dec 2015
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
on 11 Dec 2015
out4Column = [x,y,z, yourImage(:)]; should be
out4Column = [x(:), y(:), z(:), yourImage(:)];
Walter Roberson
on 11 Dec 2015
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
on 13 Dec 2015
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
on 13 Dec 2015
"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
on 13 Dec 2015
Dear Walter, Once again Thanks alot for your help.
I really appreciate it.
Regards
Sara
Sara Salimi
on 15 Dec 2015
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); "
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
on 15 Dec 2015
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
on 17 Dec 2015
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
on 17 Dec 2015
Contact the manufacturer or person that made your images to find out why they're different sizes.
Vasantha Lakshmi
on 9 Mar 2017
I need to get the voxel coordinates and intensity values of mri image which are of .mha format.How can I get it?
See Also
Categories
Find more on DICOM Format in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- 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)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)