Last active
August 29, 2015 13:58
-
-
Save kmader/9934875 to your computer and use it in GitHub Desktop.
Read in an analysis from ImageJ's Analyze Particles and group into different groups using k-means
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
imagejdata=importdata('analyzeParticlesOutput.txt','\t',1) | |
disp(imagejdata.colheaders) | |
%% parse the data in matlab | |
% A tiny piece of code to find which column the given header is in | |
% note imagej exports do not need the extra quotation marks like R does | |
findColumn=@(idstrut,colName) find(not(cellfun('isempty',strfind(idstrut.colheaders,[ colName ])))); | |
% a function to return all of the data in that column | |
getColumn=@(idstrut,colName) idstrut.data(:,findColumn(idstrut,colName)); | |
%% calculate the nearest neighbor distance and angle | |
[nndist,nnangle]=findnn(getColumn(imagejdata,'X'),getColumn(imagejdata,'Y')); | |
%% show the data | |
figure(1) | |
subplot(1,2,1); | |
plot(getColumn(imagejdata,'X'),getColumn(imagejdata,'Y'),'r.') | |
title('Point Location') | |
subplot(1,2,2); | |
hist(nndist) | |
pause(0.5) | |
%% make two groups based on area and nearest neighbor distance | |
groupId=kmeans([nndist' getColumn(imagejdata,'Area')],2,'EmptyAction','singleton'); | |
% show the groups as different colors | |
xdata=getColumn(imagejdata,'X'); | |
ydata=getColumn(imagejdata,'Y'); | |
figure(2) | |
plot(xdata(groupId==1),ydata(groupId==1),'r.') | |
hold on; | |
plot(xdata(groupId==2),ydata(groupId==2),'bo') | |
legend({'Group 1','Group 2'}); | |
hold off; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment