Dump Image Pixels into vector from coordinates
2 views (last 30 days)
Show older comments
Is there a way to use 2 vectors of pixel coordinates to quickly dump the pixel values into a 3rd vector?
Currently, I am using the following for loop, but it is very slow:
for j=1:length(x)
pixel_vals(j) = img(x(j),y(j));
end
where, 'x' and 'y' are the x,y coordinates (1xN vector form).
Many thanks!
0 Comments
Accepted Answer
More Answers (2)
Image Analyst
on 16 Apr 2012
Philip, in response to the new question in your "Answer" (not your original question), the preferred way to do this is with ismember(). Your way would take forever for an image with lots of pixels that have labels. See this code snippet from my image segmentation tutorial, BlobsDemo: http://www.mathworks.com/matlabcentral/fileexchange/?term=authorid%3A31862
% Extract only those blobs that meet our criteria, and
% eliminate those blobs that don't meet our criteria.
% Note how we use ismember() to do this.
keeperBlobsImage = ismember(labeledImage, keeperIndexes);
% Re-label with only the keeper blobs kept.
labeledDimeImage = bwlabel(keeperBlobsImage, 8); % Label each blob so we can make measurements of it
0 Comments
Philip
on 16 Apr 2012
1 Comment
Image Analyst
on 16 Apr 2012
This should have been a new question, not an answer. Comments can't have formatted code, so see my answer below.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!