Take 3x3 nearest neighbours round centroids of all spots and find the median of their mean
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hello, I have an image (TIFF) that I calculate the centroids and extract the median intensity of all these centroids.
I have the centroid positons in x1,y1 and loop through them the obtin the intensity of each spot and then take the median
Intensity(i)=IM(y1(i),x1(i)); %Centroid intensity
...
medIntensity=median(Intensity(:));

I now want to take a 3x3 nearest neighbours round each of the x1,y1 points and obtain the median of their mean.
Are there any suggestions how I achieve this.
Thanks
Jason
0 commentaires
Réponse acceptée
Matt J
le 15 Jan 2025
Modifié(e) : Matt J
le 15 Jan 2025
sz=size(IM);
centroidIdx=sub2ind(sz,y1,x1);
T=combinations(1:3,1:3);
delta=sub2ind(sz,T{:,2},T{:,1})'-(sz(1)+2);
result=median( mean( IM(centroidIdx(:) + delta),2) )
3 commentaires
Matt J
le 15 Jan 2025
Modifié(e) : Matt J
le 15 Jan 2025
IM=rand(12,14);
C=combinations(2:4:12,2:5:14);[y1r,x1r]=deal(C{:,1}, C{:,2});
sz=size(IM);
centroidIdx=sub2ind(sz,round(y1r),round(x1r)); %x1r, y1r and not integers so round
T=combinations(1:3,1:3);
delta=sub2ind(sz,T{:,2},T{:,1})'-(sz(1)+2);
A=centroidIdx(:) + delta;
[Y,X] = ind2sub(sz,A);
imagesc(IM);colormap(gray); hold on
plot(x1r,y1r,'m+',X(:),Y(:),'co','MarkerSize',11); hold off
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!