필터 지우기
필터 지우기

k-means segmentation for Raman analysis

조회 수: 11 (최근 30일)
Valeria Iazzetta
Valeria Iazzetta 2023년 11월 20일
댓글: Valeria Iazzetta 2023년 12월 13일
Good afternoon,
I hope someone can help me with this problem.
I acquired a Raman map XY of a pancreatic tumor cell, so I have a spectrum for each point of this map associate with some coordinates. Then I've realize kmeans clustering with 6 clusters.
Now I have a label (1, 2, 3, 4, 5 or 6) for each coordinates (x and y) and I want to plot them in an image with different colour. Is there a way to do this?
I attach below the coordinates for each group identified by kmeans: the first coloumn is X, while the second is Y.
What I hope to obtain is something like this:

채택된 답변

Mathieu NOE
Mathieu NOE 2023년 11월 20일
hello
I get something quite different from your expectation
first I looked at first group of excel files coordinates_group1.xlsx to coordinates_group6.xlsx
and I got this plot
code
fileDir = pwd; % current directory (or specify which one is the working directory)
S = dir(fullfile(fileDir,'coordinates_group*.xlsx')); % get list of data files in directory
S = natsortfiles(S); % sort file names into natural order , see :
%(https://fr.mathworks.com/matlabcentral/fileexchange/47434-natural-order-filename-sort)
figure
hold on
for ck = 1:length(S)
FileName=S(ck).name;
fprintf(1,'Now reading %s\n',FileName);
data = readmatrix( fullfile(fileDir, FileName));
scatter(data(:,1),data(:,2),'filled')
FileName = strrep(FileName,'_',' ');
leg{ck} = FileName;
end
legend(leg);
then I supposed that I was wrong and I had to process the remaining excel file and got somthing quite the same !
what is wrong ??
code
fileDir = pwd;
FileName='coordinates and label.xlsx';
fprintf(1,'Now reading %s\n',FileName);
data = readmatrix( fullfile(fileDir, FileName));
labels = data(:,3);
labels_range = (min(labels):max(labels));
figure
hold on
for ck = 1:numel(labels_range)
% mask = (labels==ck); % taht works
mask = (abs(labels-ck)<1e-6); % this is more robust to round off errors
leg{ck} = ['label = ' num2str(ck) ];
scatter(data(mask,1),data(mask,2),'filled')
end
legend(leg);
  댓글 수: 3
Valeria Iazzetta
Valeria Iazzetta 2023년 12월 13일
Yes, thank you. It is exactly what I want to obtain when I asked for help, so thanks so much.
Sorry if I didn't answer immediately. To get a result more similar to the image I posted, I implemented a code that associates a color at each pixel of raman map.
Mathieu NOE
Mathieu NOE 2023년 12월 13일
ok
glad you have a working solution !

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Image Analyst
Image Analyst 2023년 12월 11일
I don't know if kmeans is the best, unless you know for a fact that there are definitely exactly 6 classes present in all images. If some images might possibly not have one or more classes in them, then kmeans would be forces to find 6 anyway, and they'd be wrong.
I'd recommend you use the Classification Learner app on the Apps tab of the tool ribbon. You can try out several classification methods and pick the best one. But make sure your training set includes all possible situations including some images with all classes and some with only some of the classes present (if that is a possibility for your data).
I also don't really like kmeans because it's classifications vary from image to image. I think what you'd want is to have one fixed definition of what a class is, and then you can apply it to any image. The classifications won't vary from image to image and it will work regardless of how many classes are in any particular image. For that reason I'd prefer something like Discriminant Analysis, and I'm attaching a demo for that. The demo uses 3 features (predictors) for red, green, and blue, but you could use anything, even a list of 1000 signal values from different wavenumbers.
  댓글 수: 1
Valeria Iazzetta
Valeria Iazzetta 2023년 12월 13일
Dear Image Analyst, thanks for the answer.
I didn't apply k-means to image, but on Raman spectra. For each spectra of the raman maps that I acquired, I know spatial coordinates which I can associate with the various pixels of the image . Only then do I visualize the spatial distribution of the clusters in the cell.
For this type of analysis I cannot use LDA because I don't have reference spectra for the classes. It is an exploratory analysis.

댓글을 달려면 로그인하십시오.

제품


릴리스

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by