Reputation: 1355
I have used Hough Transforms to detect straight lines in an image. houghlines
function returns line endpoints which one can plot. However i wish to remove the detected line from the image by creating a black line on the image of pixel width Two.
Here is a sample plot of Hough line onto the image.
This is a sample output. I want to set all the green pixels to zero. I have already tried using this Bresenham code to get all the points between two end points of the line and setting them to zero. However the results are not as expected.
Upvotes: 1
Views: 201
Reputation: 944
There is different possible approaches to do so. A very simple approach is to use im2bw to set a threshold.
I = imread('fH7ha.jpg');
figure;
subplot 121; imshow(I); title('before')
I = rgb2gray(I);
I = im2bw(I, 0.9);
subplot 122; imshow(I); title('after')
However this is a bit inaccurate since some part of the line are outside of your image, you can then isolate the green area and dilate it using imdilate:
I = imread('fH7ha.jpg');
figure;
subplot 131; imshow(I); title('before')
green_pixels = I(:,:,2)-I(:,:,1)-I(:,:,3);
green_pixels = im2bw(green_pixels, 0.1);
se = strel('disk', 2);
green_pixels = imdilate(green_pixels, se);
subplot 132; imshow(green_pixels); title('green pixels')
I = rgb2gray(I);
I(green_pixels) = 0;
subplot 133; imshow(I); title('after')
Upvotes: 1