Problem when converte image to binary

1 view (last 30 days)
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 (1)

Ganapathi Subramanian
Ganapathi Subramanian on 30 Aug 2023
Hi Dekel,
It is my understanding that you are working on an image processing application and require guidance to resolve the problem of filtering out white images. The problem you are facing will not be relevant to MATLAB and might be something else. The effectiveness of your code may vary depending on the image characteristics. You may need to adjust the threshold values, morphological operations and other parameters to achieve optimum results.

Community Treasure Hunt

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

Start Hunting!