image analysis using kmeans

7 次查看(过去 30 天)
Sara Anis
Sara Anis 2019-7-2
回答: Satwik 2025-4-21
Hi, I have a .hdf image that i need to analyse. The image has two spots on it that i need to be able to select and compare the intensity of. I first tried to use kmeans clustering and the insegkmeans function but still ran into problems finding the x,y centers of the spots and being able to select that cluster to compare. Can someone please help me.

回答(1 个)

Satwik
Satwik 2025-4-21
Here is an workflow which can be used for analyzing two points in a .HDF image.
1. Load the HDF Image:
img = h5read('your_image.hdf', '/ImageData'); % Adjust dataset name as needed
img = squeeze(img); % Remove singleton dimensions
img = double(img);
2. Segment the Spots with K-means:
[idx, C] = kmeans(img(:), 2);
clusters = reshape(idx, size(img));
spotMask = clusters == find(C == max(C)); % Assume brighter spots
3. Find Centers and Intensities:
props = regionprops(spotMask, img, 'Centroid', 'MeanIntensity');
imshow(img, []); hold on;
for k = 1:length(props)
plot(props(k).Centroid(1), props(k).Centroid(2), 'r+', 'MarkerSize', 15);
fprintf('Spot %d: Intensity %.2f\n', k, props(k).MeanIntensity);
end
hold off;
I hope this helps!

类别

Help CenterFile Exchange 中查找有关 Statistics and Machine Learning Toolbox 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by