7
Saving the path
The second part of the project was to create a program (MatLab m-file) which saves the curve that
the laser pointer draws in the paper. The curve was to be saved as set of points in one picture. From
this picture we will be able to extract the error for the desired path and the actual path. This error
will be used for Iterative Learning Control.
This kind of function is actually really easy to implement. The code (‘savePath.m’) I wrote looks
like this:
imSize = size(oldImage);
imSize2 = size(newImage);
if(imSize-imSize2 ~= 0)
errordlg('Image sizes do not match');
end
pathImage = oldImage;
for i=1 : imSize(2)
for j=1 : imSize(1)
%check if pixel is red, then save it
if(newImage(j,i,1) > 245 && newImage(j,i,2) > 150
&& newImage(j,i,3) > 150)
pathImage(j,i,1) = newImage(j,i,1);
pathImage(j,i,2) = newImage(j,i,2);
pathImage(j,i,3) = newImage(j,i,3);
end
end
end
In the for-loop we go thru every pixel of the picture, and if the pixel is red, it is copied to
‘pathImage’. The pixel is considered red if the red value (of RGB pixel) is over 245 and green and
blue values are under 150.
NOTE! If you want to change the sensitivity of the pixel saving, you can change the values in the if-
statement
if(newImage(j,i,1) > 245 && newImage(j,i,2) > 150 && newImage(j,i,3) > 150),
where
newImage(j,i,1) is the red channel, newImage(j,i,2) is the green channel and
newImage(j,i,3) is the blue channel of the pixel.
NOTE! The line
pathImage = oldImage;
is unnecessary. It can be removed, if variable ‘oldImage’ on the first line is changed to ‘pathImage’.
Also, if this line is removed, you must remove all of the lines
oldImage = pathImage;
Comentários a estes Manuais