Problem when converte image to binary

1 view (last 30 days)
Dekel Mashiach
Dekel Mashiach on 3 Jun 2022
Edited: Dekel Mashiach on 3 Jun 2022
I designed a code in image processing for an autonomous vehicle that needs to track between two white stripes. I designed the code so that I actually searched the matrix of the image from the camera for the highest values (white color) and anything that is not white , I turned אם black (= 0). The problem is that sometimes it recognizes other things in the image in white so it is difficult for it to create the trajectory. How can I fix this?
grayImage = rgb2gray(rgbImage);
figure
imshow(grayImage)
grayImage(grayImage<170)=0;
if ndims(grayImage) == 3
grayImage = grayImage(:, :, 1);
end
figure
imshow(grayImage, []);
impixelinfo;
mask = logical(grayImage > 140 & grayImage < 255);
mask = bwareafilt(mask, 2);
mask = bwskel(mask);
figure
imshow(mask);
mask2 = imopen(mask, strel('line', 3, 0));
mask(mask2) = 0;
mask = logical(mask);
figure
imshow(mask);

Answers (0)

Community Treasure Hunt

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

Start Hunting!