To convert a color RGB image to grayscale, use ‘rgb2gray’. 

 

For example:

 

im = imread(‘image.bmp’);  % im is m x n x 3 matrix of RGB values

grayim = rgb2gray(im);       % grayim is m x n matrix of intensities

 

 

 

 

An example to show the image and plot a line from houghlines on top of it, based on the endpoints returned:

 

%… get lines with houghlines, say there are two:

 

lines =

 

1x2 struct array with fields:

    point1

    point2

    theta

    rho

 

% to plot the first one, extract the endpoints from the struct

 

x1 = lines(1).point1(1);

y1 = lines(1).point1(2);

 

x2 = lines(1).point2(1);

y2 = lines(1).point2(2);

 

imshow(im);

hold on;

 

plot([x1, x2], [y1, y2], ‘r.-‘);  % draws red line connecting two points, with dots at the endpoints