필터 지우기
필터 지우기

How to Insert a Dotted Line using InsertShape?

조회 수: 19 (최근 30일)
Sally Weston
Sally Weston 2019년 7월 1일
편집: Wei Huang 2023년 11월 8일
Hello. I'm trying to insert a dotted line onto my figure (A) but struggling with the line spec. Here is my line of code. Normally I'll put 'k--' or 'LineSpec','--' but error says "'LineSpec' is not a recognized parameter". Please can you help me?? Thank you, Sally
A = insertShape(A,'line',[1 168.5 301 168.5],'Color','black','LineWidth',6)

답변 (2개)

Abhisek Pradhan
Abhisek Pradhan 2019년 7월 16일
The insertShape MATLAB function doesn’t have the functionality to insert a dotted line over a picture.
You can try a workaround mentioned below.
imshow(A);
hold on;
line([1,301],[168.5,168.5],'Color','r','LineStyle','--','LineWidth',6);
Refer line and insertShape for more information.

Wei Huang
Wei Huang 2023년 11월 8일
편집: Wei Huang 2023년 11월 8일
Here is a way you can do this by interpolating between the points of your solid line:
% Create some image
I = uint8(zeros(400,400));
% Points defining solid line
solidLine = [1 168.5 301 168.5];
% Interpolating solid line to with n number of points
n = 20;
dashLine = [linspace(solidLine(1),solidLine(3),n);...
linspace(solidLine(2),solidLine(4),n)];
% Account for odd number of interpolated points
if mod(n,2)
n = n-1;
dashLine = dashLine(:,1:end-1);
end
% Reshape dash line for insertShape
dashLine = reshape(dashLine,4,n/2)';
I = insertShape(I,"line",dashLine,'Color','r','LineWidth',6);
imshow(I);

카테고리

Help CenterFile Exchange에서 Graphics Object Properties에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by