# How to Remove Double Lines Detected Along the Edges by Edge Detector?

I'm trying to take real time input for hand gestures with web cam, then processing the images to feed them to a neural network. I wrote this processing function to make the hand features look prominent:

def image_processing(image, count):
roi = image[42:338, 2:298]
cv2.imwrite('a/'+str(count)+'.png', roi)

gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
blur = cv2.GaussianBlur(gray,(5,5),2)

ret, res = cv2.threshold(th3, 225, 255, cv2.THRESH_BINARY_INV+cv2.THRESH_OTSU)
res = cv2.Canny(res,100,200)
cv2.imshow("Canny", res)
cv2.imwrite('a/'+str(count)+'.png', res)


--Edit--

The input and the output images are as follows :

It's obvious that double lines, instead of one, are detected along the edges. I want to make them single. If I apply just Canny edge detection algo, then the edges are not very prominent.

• Have you considered using a max filter? Apr 2 at 22:05
• Could you share the input image?
– Royi
Apr 2 at 23:43
• @Royi : Shared. Plz check the edit section. Apr 3 at 7:58

I ran the following code:

clear();
close('all');
vBlurStd = [0, 0.1, 0.5, 0.75, 1, 1.25, 1.5, 1.75, 2];

mII = sum(cat(3, 0.299, 0.587, 0.114) .* mI, 3); %<! Y (Luminosity like channel)

hFigure = figure('Position', [100, 100, 1200, 900]);
hTiledChartLayout = tiledlayout(3, 3);

kk = 0;
for ii = 1:3
for jj = 1:3
kk = kk + 1;
if(kk == 1)
mE = edge(mII, 'canny');
else
mE = edge(imgaussfilt(mII, vBlurStd(kk)), 'canny');
end
nexttile();
imshow(mE);
end
end



This is the result:

### What Does the Script?

1. We set an array of different blur radius to evaluate the algorithm at - vBlurStd.
2. We load the image and convert it into Double in the range [0, 1] - mI = im2double(imread('bCfdb.png'));
3. We extract the Y channel from the YCbCr color model - mII = sum(cat(3, 0.299, 0.587, 0.114) .* mI, 3);.
4. The algorithm is basically blurring the image with Gaussian Blur and then applying Canny Edge Detector - edge(imgaussfilt(mII, vBlurStd(kk)), 'canny');.

The images are left to right, top down by their blur radius.

• Hi, I'm using Python. Did you write just the algo or is it in language other than Python? Apr 3 at 14:57
• It's MATLAB. But you can get very similar results with Python. Just extract the Y channel, Do a small blur and then Canny Edge Detection.
– Royi
Apr 3 at 17:08
• Could you plz convert it into Python? I'm absolutely unaware of Matlab syntax which is why I don't understand how the code works. Apr 3 at 18:56
• @Debbie, I described the algorithm. All the ingredients are already in your code.
– Royi
Apr 4 at 4:27
• Thanks..I'll check. Apr 4 at 8:34