how to draw a line from the centre of the image to its border

1 次查看(过去 30 天)
In the given image, i plotted 6 points on its border manually. a random point is selected in the image. My objective is to connect all those 6 points with this random point. how to connect those by lines.

采纳的回答

Image Analyst
Image Analyst 2012-9-1
编辑:Image Analyst 2012-9-1
Did you try the line() function? That will plot in the overlay. If you want the line burned into the image use the imline() function's createMask() method.
% Demo to write a line into the overlay of an image,
% and then to burn the overlay into the image.
%----- Initializing steps -----
% Clean up
clc;
clear all;
close all;
workspace; % Display the workspace panel.
hasIPT = license('test', 'image_toolbox');
if ~hasIPT
% User does not have the toolbox installed.
message = sprintf('Sorry, but you do not seem to have the Image Processing Toolbox.\nDo you want to try to continue anyway?');
reply = questdlg(message, 'Toolbox missing', 'Yes', 'No', 'Yes');
if strcmpi(reply, 'No')
% User said No, so exit.
return;
end
end
% Display images to prepare for the demo.
monochromeImage = imread('pout.tif');
subplot(2, 2, 1);
imshow(monochromeImage);
title('Original Image');
subplot(2, 2, 2);
imshow(monochromeImage);
title('Original Image with line in overlay');
set(gcf, 'units','normalized','outerposition',[0 0 1 1]); % Maximize figure.
set(gcf,'name','Image Analysis Demo','numbertitle','off')
%----- Burn line into image -----
burnedImage = imread('pout.tif');
% Create line mask, h, as an ROI object over the image.
hLine = imline(gca,[10 100],[10 100]); % Second argument defines line endpoints.
% Create a binary image ("mask") from the ROI object.
binaryImage2 = hLine.createMask();
% Display the line mask.
subplot(2, 2, 3);
imshow(binaryImage2);
title('Binary mask of the line');
% 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, 2, 4);
imshow(burnedImage);
title('New image with line burned into image');
  3 个评论
Sivakumaran Chandrasekaran
i found that the code works for a single line. can we use for drawing multiple lines
Image Analyst
Image Analyst 2012-9-1
Of course. Why don't you just package it into a function where you can pass in the two endpoint coordinates?

请先登录,再进行评论。

更多回答(0 个)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by