From what I understand, you have a set of points representing an ellipse, and you would to draw them directly inside an image matrix (not just display them on screen).
For this, you can use the POLY2MASK function to convert the ellipse into a binary mask. Then by computing its perimeter, this will give us a binary mask representing only the pixels that constitute the ellipse, which is applied to the image to set the color of the pixels.
Consider the example below. I am using the function calculateEllipse.m from a previous question here on SO:
%# some image
I = imread('pout.tif');
sz = size(I);
%# ellipse we would like to draw directly on image matrix
[x,y] = calculateEllipse(100,50, 150,50, 30, 100);
%# lets show the image, and plot the ellipse (overlayed).
%# note how ellipse have floating point coordinates,
%# and also have points outside the image boundary
figure, imshow(I)
hold on, plot(x,y, 'LineWidth',2)
axis([-50 250 -50 300]), axis on
%# create mask for image pixels inside the ellipse polygon
BW = poly2mask(x,y,sz(1),sz(2));
%# get the perimter of this mask
BW = bwperim(BW,8);
%# use the mask to index into image
II = I;
II(BW) = 255;
figure, imshow(II)
This should give you superior results to simply rounding the coordinates of x
and y
(plus it handles out-of-boundary points for us). Make sure to read the algorithm section of POLY2MASK to see how it works on a subpixel level.
EDIT:
if you are working with an RGB image (3D matrix), the same applies, you only need to change the last part where we use the binary mask :
%# color of the ellipse (red)
clr = [255 0 0]; %# assuming UINT8 image data type
%# use the mask to index into image
II = I;
z = false(size(BW));
II( cat(3,BW,z,z) ) = clr(1); %# R channel
II( cat(3,z,BW,z) ) = clr(2); %# G channel
II( cat(3,z,z,BW) ) = clr(3); %# B channel
figure, imshow(II)
Here is yet another way:
%# use the mask to index into image
II = I;
BW_ind = bsxfun(@plus, find(BW), prod(sz(1:2)).*(0:2));
II(BW_ind) = repmat(clr, [size(BW_ind,1) 1]);
figure, imshow(II)