Kmeans Clustering for MATLAB MRI Data

3 vues (au cours des 30 derniers jours)
Preeti
Preeti le 20 Avr 2020
Modifié(e) : Michael le 26 Mai 2020
Hello!
I am trying to group the pixels in slice 16 axial view MRI data into 4, 8 and 20 clusters respectively using kmeans clustering. I have squeezed, reshaped and created a for loop, however I am getting an error. Any help would be great!
Thanks!

Réponses (1)

Michael
Michael le 26 Mai 2020
Modifié(e) : Michael le 26 Mai 2020
Hello Preeti,
I see a number of issues with your code.
First off, the call to squeeze and he two calls to reshape have no effect on any variables you can use later in the code. In MATLAB, argmuents are passed to functions by value, so if you don't store the output of the squeeze and reshape functions, there's no use in calling them. If I understand the rest of the function, this isn't useful anyway.
Second, you appear to be trying to "double dereference" the variable D inside your for loop. MATLAB doesn't support this functionality.
Lastly, I don't think that kmeans is going to give you the results you are looking for in this case. If this 16th slice really is 2D image data, then you've eliminated a fair amount of data by finding the max over any given column. The code as written (with the issues I've described above resolved) would simply break the maximums into 4 ranges, and tell you which of the maximums belong to each range. So, you'd end up with the a 1-dimensional cross section of the image data, split into segments based on the maximum in each column. This doesn't seem useful unless I'm not understanding the application. And your call to imshow is going to show a single column of information.
Without trying to predict what you are hoping to do with the output of this function, here is what you've written, with the errors and extraneous code removed. What this code will do is "colorize" the slice using the colors k, r, g, and b.
Hope this helps!
-- Mike
load mri
s16 = D(:,:,16); % Pull the slice out of the data cube.
idx = kmeans(s16(:), 4);
imshow(reshape(idx, size(s16)), [0 0 0;eye(3)]);

Catégories

En savoir plus sur MRI dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by