# Making a line visible over an image in MATLAB5

Posted by Doug Hull,

It can be difficult to see a line that is drawn over an image. The line is often lost in the background colors. That is why cursors are colored as they are, so that they are visible on any background. I demonstrate some code that makes a line more visible with the same technique. function h = cursorLine(x,y,innerThickness, outerThickness) if nargin == 2 innerThickness = 2; outerThickness = 4; end h.thick = line(x,y); h.thin = line(x,y); set(h.thick, 'color', [1 1 1]); set(h.thin , 'color', [0 0 0]); set(h.thick, 'linewidth', outerThickness); set(h.thin , 'linewidth', innerThickness); 

Jonathan replied on : 1 of 5

Doug,

This is a nice tip. Thank you. I especially like that you made the code available outside the video. Now I can see the tip at a glance.

~Jonathan

Dan replied on : 2 of 5

I think it would be more useful to have two lines sharing a common thickness (which the user could adjust) and use different lifestyles. One line would be solid, the other dashed.

Doug replied on : 3 of 5

@Dan,

That is the great thing here. You have the code, give it a try!

Doug

Anand P replied on : 4 of 5

Thanks for the share, Doug

function cursorLine(x,y,innerThickness, outerThickness)
% Making a line visible over an image in MATLAB
% x : X axis co-ordinates of the points on the line
% y : Y axis co-ordinates of the points on the line
% innerThickness : Thickness of the black line (inner line)
% outerThickness : Thickness of the white line (outer line)

% Setting default values if no. of inputs are less than specified
if nargin == 2
innerThickness = 2;
outerThickness = 4;
else
if nargin innerThickness
h.thick = line(x,y);
set(h.thick, ‘color’, [1 1 1]);
set(h.thick, ‘linewidth’, outerThickness);
end

% Display black line only if inner line width is more than zero
if innerThickness > 0
h.thin = line(x,y);
set(h.thin , ‘color’, [0 0 0]);
set(h.thin , ‘linewidth’, innerThickness);
end
end

Doug replied on : 5 of 5

@Anand

Look like good changes to me.

Doug

What is 1 + 6?

Preview: hide