Centroid Location is incorrect when edited in actual image data
Show older comments
I'm trying to use the image processing toolbox to find the weighted centroid locations of a given binary image. Once I've found this the centroid plots correctly, however the x & y coordinates of the centroid location don't seem to correspond to the original image data directly.
When I change the value of the centroid location in the original image data and then show the edited image, the area I've edited is not where the centroid location was supposed to be.
imagedata = imread('C:\Program Files\MATLAB\R2009b\toolbox\images\imdemos\rice.png')
blackwhite = ~(imagedata<150);
[x,y,handles.ibw2] = bwselect(blackwhite, 4);
s = regionprops(handles.ibw2,'centroid');
centroids = cat(1,round(s.Centroid));
hold on
gcf
plot(centroids(:,1), centroids(:,2), 'b*');
axis image
Here it plots the centroid correctly on the figure. When using that same centroid information to edit the image however, it changes the location. Am I needing to normalize this somehow, or is there information about the centroid that I'm not understanding? Here's the simple code I used to change the binary value at the centroid location.
blackwhite(centroids(:,1),centroids(:,2)) = 1
imshow(blackwhite)
Accepted Answer
More Answers (0)
Categories
Find more on Image Arithmetic in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!