Extracting image coordinates from binary image
Mostrar comentarios más antiguos
I'm new to matlab so apologies if this has been asked before.
I have a grayscsale image (of a tooth) that I need to extract the following data from;
Image centroid Max/Min x Max/Min y
I read the image into matlab and converted it to binary as below
im = 'C:\users\simon\desktop\w14.png' imread(im) bw = im2bw(imread(im),0.98)
inverted the data values so the tooth pixels have a value of 1 and the background is 0
Wrote the x and y values out by
[x y]=find([bw])
If i then take the mean of x and y, or use stats=regionprops(bw) to get the same and then plot the corresponding point back on the image it plots outside of the tooth.
Am i doing something wrong, or is this likely to be something wrong with the data itself?
Thanks!
Simon
Respuesta aceptada
Más respuestas (1)
Image Analyst
el 1 de Feb. de 2015
Try this:
labeledImage = bwlabel(bw);
blobMeasurements = regionprops(labeledImage, 'Centroid');
% We can get the centroids of ALL the blobs into 2 arrays,
% one for the centroid x values and one for the centroid y values.
allBlobCentroids = [blobMeasurements.Centroid];
centroidsX = allBlobCentroids(1:2:end-1);
centroidsY = allBlobCentroids(2:2:end);
% Put the labels on the rgb labeled image also.
for k = 1 : numberOfBlobs % Loop through all blobs.
plot(centroidsX(k), centroidsY(k), 'b*', 'MarkerSize', 15);
if k == 1
hold on;
end
text(centroidsX(k) + 10, centroidsY(k),...
num2str(k), 'FontSize', fontSize, 'FontWeight', 'Bold');
end
2 comentarios
SimonW
el 1 de Feb. de 2015
Image Analyst
el 1 de Feb. de 2015
Yep, you got it. To add measurements, list them in the arg list:
blobMeasurements = regionprops(labeledImage, 'Centroid',...
'MajorAxisLength', 'MinorAxisLength');
Categorías
Más información sobre Region and Image Properties en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!