fuzzy clustering only on pixels > zero
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
I have an image in which I have isolated the tumor region using thresholding (img 1) . Now im trying to use fuzzy clustering to cluster the pixels in just the tumor ROI but not the black background (basically ignore any pixels = 0 in clustering). The code I am using is not outputting any clustered images, because its throwing an error that "to reshape the number of elements must not change."
Can someone tell me what I am doing wrong?
% cluster the image without clustering the black background
fuzzyT2 = mriAdjust(:,:,15);
[y, x] = find(fuzzyT2)
idx = fuzzyT2 > 0 %creates a mask for true value for all nonzero pixels
z = fuzzyT2(idx);
%% fuzzy c-means
G = 4
z = double(z)
[cluster_idx, cluster_center, obj] = fcm(z, G)
% reshape into four 2-D array
cluster1 = cluster_center(1,:);
cluster2 = cluster_center(2,:);
cluster3 = cluster_center(3,:);
cluster4 = cluster_center(4,:)
imIDX1 = reshape(cluster1, size(idx));
imIDX2 = reshape(cluster2, size(idx));
imIDX3 = reshape(cluster3, size(idx));
imIDX4 = reshape(cluster4, size(idx));
subplot(2,2,1), imshow(img_1), title('cluster 1')
subplot(2,2,2), imshow(img_2), title('cluster 2')
subplot(2,2,3), imshow(img_3), title('cluster 3')
subplot(2,2,4), imshow(img_4), title('cluster 4')
Risposte (1)
Image Analyst
il 5 Nov 2019
idx has the same number of elements as (the badly-named) I.
However z does not. Since some of the binary image idx is presumably false, z will have fewer elements than idx and I. That's why the reshaping does not work.
To get the classified image the same size as the original, you will have to pull a few tricks that I don't have time to tell you since it's late at night, but hopefully you can figure it out before I come back tomorrow.
1 Commento
Image Analyst
il 7 Nov 2019
I don't have the fuzzy toolbox so I suggest you just step through with the debugger and see that they have different sizes and shapes.
Vedere anche
Categorie
Scopri di più su Fuzzy Inference System Modeling in Help Center e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!