In addition to the post for Harris detector I will share some code for marking the objects and points in an image. When I needed some ready-to-use Matlab function (R2009b) I did not find anything. There is such a block in the Simulink Image Processing blockset, however there is no equivalent M-code function in Matlab. So, I was forced to create my own marker function to view the results of my code and to develope my programs.
So here is the code for "+" marker :
function
[draw_img]=draw_cross_marker(img,y,x,R,G,B)
% Draw
Marker
%Drawing
Markers in the image img. The marker is +. There is no other choice.
%The color
of the marker is defining by R,G,B values.R,G and B values
%should be
in range [0,255].
%y and x
are vectors with equal lenghts containing coordinates of y and x in matrix
coordinate
%system of
the points where should be put a marker. The function take a raw
%image
"img" and return the same image with markers drawn on it.
[size_m,~]=size(y);
for i=1:1:size_m
img(y(i),x(i),1)=R;
img(y(i),x(i),2)=G;
img(y(i),x(i),3)=B;
img(y(i)+1,x(i),1)=R;
img(y(i)+1,x(i),2)=G;
img(y(i)+1,x(i),3)=B;
img(y(i)-1,x(i),1)=R;
img(y(i)-1,x(i),2)=G;
img(y(i)-1,x(i),3)=B;
img(y(i),x(i)+1,1)=R;
img(y(i),x(i)+1,2)=G;
img(y(i),x(i)+1,3)=B;
img(y(i),x(i)-1,1)=R;
img(y(i),x(i)-1,2)=G;
img(y(i),x(i)-1,3)=B;
end
draw_img=img;
And here is the code for rectangular maker:
function
[draw_img]=draw_rectangle_marker(img,RectSize,y,x,R,G,B)
% Draw
Marker
%[draw_img]=draw_rectangle_marker(img,RectSize,y,x,R,G,B)
%Drawing
Markers in image img. The marker is a rectangle. There is no other choice.
%The color
of the marker is defining by R,G,B values.R,G and B values
%should be
in range [0,255]. RectSize - the size of the rectangle.
%"y"
and "x" are vectors with equal lenghts containing coordinates of y
and x in matrix coordinate
%system of
the points where should be put a marker.
%The
function take raw a image img and return the same image with markers on it.
SemiSize=round(RectSize/2);
y1=y-SemiSize;
x1=x-SemiSize;
for
i=x1:1:x1+RectSize
for j=y1:1:y1+RectSize
if
(((i==x1)||(i==x1+RectSize))||((j==y1)||(j==y1+RectSize)))
img(j,i,1)=R;
img(j,i,2)=G;
img(j,i,3)=B;
end
end
end
draw_img=img;
The result of the cross marker function can be seen in the Feature Points Detection - Harris Detector post.
Няма коментари:
Публикуване на коментар