No BSD License  

Highlights from
GeoML

image thumbnail
from GeoML by Gabriele Lombardi
A general morphable template tool for image segmentation.

impixels(img,P)
function vals = impixels(img,P)
% IMPIXELS  Get the values of image pixels at defined points.
%
%  Given an image and a set of points the image values are returned in a
% matrix containing all the channels on the rows and the pixels values on
% the colums.
%
%  Params
%  ------
% IN:
%  img  = The image.
%  P    = The points.
% OUT:
%  vals = The pixels values.

% Check params:
if nargin<2 error('An image and a set of points must be provided!'); end

% Converting the points:
P = ceil(points2dnormalize(P));

% The image and points sizes:
[h,w,c] = size(img);
npts = size(P,2);

% Computing output:
vals = zeros([c,npts]);

% Iterating on pixels:
for ind=1:npts
    % Check if the point is in the pixel:
    if P(1,ind)>0 && P(2,ind)>0 && P(1,ind)<w && P(2,ind)<h
        % Get the pixel value:
        vals(:,ind) = img(P(2,ind),P(1,ind),:);
    else
        % Set the value to NaN:
        vals(:,ind) = NaN;
    end
end

Contact us at files@mathworks.com