How to Insert a Dotted Line using InsertShape?

24 Ansichten (letzte 30 Tage)
Sally Weston
Sally Weston am 1 Jul. 2019
Bearbeitet: Wei Huang am 8 Nov. 2023
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)

Antworten (2)

Abhisek Pradhan
Abhisek Pradhan am 16 Jul. 2019
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 am 8 Nov. 2023
Bearbeitet: Wei Huang am 8 Nov. 2023
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);

Kategorien

Mehr zu Graphics Object Properties finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by