Say I have an RGB image rgband a list of spatial coordinates coords. I would like to retrieve the values of pixels in the spatial coordinates, for example, [x1 y1], [x2 y2]and [x3 y3]. For RGB images, I can do this using:
rgb = imread('sample.jpg')
coords = [x1 y1; x2 y2; x3 y3];
pixelData = impixel(rgb, coords(:,1), coords(:,2));
Returns the red, green, and blue values of the specified pixels in the image.
impixelonly works for color (RGB) images. But I want to extract the pixel values from the grayscale image I. I can do this using a loop forlike this
for i = 1:size(coords,1)
pixelData(i,:) = I(coords(i,2), coords(i,1));
end
I would like to avoid using loops for. Is there any other way to do this?
imstats = regionprops(mask, I,'PixelValues');also works, but first I need an image mask.