MATLAB: Find pixel coordinates value of a centroid

image segmentation

[EDIT: Fri May 13 20:58:34 UTC 2011 – Reformat – MKF]
I want to find the x n y coordinates and pixel value of the centroid. Here is the code I have:
I = imread('mobil.png');
%I2 = imtophat(I,strel('disk',15));
level = graythresh(I);
bw = im2bw(I,level);
I2 = 1 - bw;
I2 = bwareaopen(I2, 200);
I3 = imfill(I2, 'holes');
s = regionprops(I3, 'centroid');
centroids = cat(1, s.Centroid);
imshow(I3)
hold on
plot(centroids(:,1), centroids(:,2), 'b*')
hold off
impixelinfo
The car is :

Best Answer

centroids = round(centroids);
cent_vals = Inotbw(sub2ind(size(Inotbw),centroids(:,2),centroids(:,1)))