Vertical lines artifacts while using ShapeInserter of Vision toolbox ?
3 views (last 30 days)
Show older comments
Hello everyone,
I am trying to solve a problem that you guys may have had if you used the toolbox.
I am using ShapeInserter to draw arrows on an image generated out of a code.
I use a function "arrows_coordinates" to provide polygons coordinates of an arrow with start point, end point and, line thickness and width and length of the arrow in pixels.
Then, I draw the polygoned arrows in the image using step but sometimes undesired vertical lines on the image appear coming with arrows, not all of them). Attached is an example of an image with 5 arrows in the center of the image and all of them having the vertical line problem.
All of them haveing the problem :
Not all of them having the problem :
Detail :
From the same examples here is the useful code :
% create arrows
shapeInserter = vision.ShapeInserter('Shape','Polygons',...
'BorderColor','Custom',...
'CustomBorderColor', [255 0 0],...
'Fill', 1,...
'FillColor','Custom',...
'CustomFillColor', [255 0 0],...
'Opacity', 1,...
'Antialiasing', 1);
% id which show arrows:
for id = 1:npoints
arrows(id,:) = int32(arrow_coordinates(x_mosaic(id)-25,...
y_mosaic(id)-25,...
x_mosaic(id)-1,...
y_mosaic(id)-1,...
3, 10, 12));
end
mosaic = step(shapeInserter, mosaic, arrows);
"x_mosaic" and "y_mosaic" is the array with the coordinates of points showed by the arrows and "mosaic" is the image
The arrow_coordinate function :
function tab = arrow_coordinates(x1,y1,x2,y2,LW,W,H)
% tab = array with points coordinates of the polygoned arrow
%
% x1,y1 = start point of the arrow
% x2,y2 = end point of the arrow
% LW = line thickness in pixels
% W = width of arrow head in pixels
% H = length of arrow head in pixels
opp = y2-y1;
adj = x2-x1;
hyp = ((y2-y1)^2+(x2-x1))^0.5;
xa = x2;
ya = y2;
xb = x2 - H*adj/opp - W/2*opp/hyp;
yb = y2 - H*opp/hyp + W/2*adj/hyp;
xc = x2 - H*adj/hyp - LW/2*opp/hyp;
yc = y2 - H*opp/hyp + LW/2*adj/hyp;
xd = x1 - LW/2*opp/hyp;
yd = y1 + LW/2*adj/hyp;
xe = x1 + LW/2*opp/hyp;
ye = y1 - LW/2*adj/hyp;
xf = x2 - H*adj/hyp + LW/2*opp/hyp;
yf = y2 - H*opp/hyp - LW/2*adj/hyp;
xg = x2 - H*adj/hyp + W/2*opp/hyp;
yg = y2 - H*opp/hyp - W/2*adj/hyp;
tab = [xa ya xb yb xc yc xd yd xe ye xf yf xg yg];
end
I keep looking after the problem I will tell you here if I find something. This post is in case some of you know or are interested in the problem.
0 Comments
Answers (3)
Amichay amitay
on 13 Mar 2018
Edited: Amichay amitay
on 13 Mar 2018
This seems to be a bug in this feature when using LineWidth that is larger than 1. I managed to bypass this by adding the line (in your case arrow) on a image of the same size but zero values. Then used imdilate to make the lines wider. Then used the non-zero values to write the original image. For example, adding on Image Img lines (defined in LinesVar) with width 10 is as follows: Tmp=Img*0; shapeInserter = vision.ShapeInserter('Shape', 'Lines', 'BorderColor', 'White','LineWidth',1); Tmp = step(shapeInserter, Tmp, int32(LinesVar)); Tmp = imdilate(Tmp,strel('disk',5)); Img (Tmp>0)= 255; %for example
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!