COMPGROUPS.NET | Search | Post Question | Groups | Stream | About | Register

### plotting lin on image

• Email
• Follow

```Hello,
I want to draw a line on my image by changing its pixel value.
I have found four coordinates x1,y1,x2,y2.
my image frame is stored in z.
How do i change pixels in z so that i get a line ON image from x1,y1 to x2,y2.
Regards,
Meenaxi Momaya
```
 0

See related articles to this posting

```Meenaxi Momaya:
Either use the line() function to draw it into the overlay above the
image, or use the "Bresenham line algorithm" (http://en.wikipedia.org/
wiki/Bresenham%27s_line_algorithm)  to draw the line into the actual
image, or use imline, as in this demo (requires the Image Processing
Toolbox):
IMPORTANT: Be sure to join long lines that the newsreader splits into
two.

% Demo to write an ellipse and a line into the overlay of an image,
% and then to burn those overlays into the image.

%----- Initializing steps -----
% Clean up
clc;
clear all;
close all;
workspace; % Display the workspace panel.

% Display images to prepare for the demo.
subplot(2, 4, 1);
imshow(monochromeImage);
title('Original Image');
subplot(2, 4, 2);
imshow(monochromeImage);
title('Original Image with ellipse in overlay');
subplot(2, 4, 5);
imshow(monochromeImage);
title('Original Image');
subplot(2, 4, 6);
imshow(monochromeImage);
title('Original Image with line in overlay');
set(gcf, 'Position', get(0, 'ScreenSize')); % Maximize figure.
set(gcf,'name','Demo by ImageAnalyst','numbertitle','off')

%----- Burn ellipse into image -----
% Create elliptical mask, h, as an ROI object over the second image.
subplot(2, 4, 2);
hEllipse = imellipse(gca,[10 10 50 150]); % Second argument defines
ellipse shape and position.
% Create a binary image ("mask") from the ROI object.
subplot(2, 4, 3);
imshow(binaryImage);
% Let's try to add some text.  (Doesn't work)
% hText = text(50, 100, 'Line of Text');
% binaryImage = binaryImage & textMask;
% imshow(binaryImage);
% Burn ellipse into image by setting it to 255 wherever the mask is
true.
monochromeImage(binaryImage) = 255;
% Display the image with the "burned in" ellipse.
subplot(2, 4, 4);
imshow(monochromeImage);
title('New image with ellipse burned into image');

%----- Burn line into image -----
% Create line mask, h, as an ROI object over the second image in the
bottom row.
subplot(2, 4, 6);
hLine = imline(gca,[10 100],[10 100]); % Second argument defines line
endpoints.
% Create a binary image ("mask") from the ROI object.
subplot(2, 4, 7);
imshow(binaryImage2);
% Burn line into image by setting it to 255 wherever the mask is true.
burnedImage(binaryImage2) = 255;
% Display the image with the "burned in" line.
subplot(2, 4, 8);
imshow(burnedImage);
title('New image with line burned into image');

```
 0