Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

background color affecting contour detection

I have been successful in detecting contours and drawing those back on the original image.

Here is my original image: Original Image

Portion of Python script where I detect contours:

image = cv2.imread("/Users/donaldkeidel/Downloads/input_template_masked.jpg")
# grayscale the image
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
# apply a Gaussian blur
blur = cv2.GaussianBlur(gray, (3, 3), 0)
# threshold the image
(t, binary) = cv2.threshold(blur, 100, 255, cv2.THRESH_BINARY)
# find contours
(_, contours, _) = cv2.findContours(binary, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
image_cropped_contoured_drawn = cv2.drawContours(image.copy(), contours, -1, (0, 255, 0), 3)
cv2.imwrite("F4GSCZQJHG7K_template_masked_contoured_exploration.jpg", image_cropped_contoured_drawn)

Here is the output image: Contoured Image

As you can see in the image, almost all the contours were captured where the background color is a lighter gray. However, where the background is an almost black in the middle of the image, less contours were detected.

Is there some techniques that can be applied to detect more of these contours? I played with the threshold value and found that 100 works the best. I also used a few other values for the parameters in the GaussianBlur method.

Thank you.

background color affecting contour detection

I have been successful in detecting contours and drawing those back on the original image.

Here is my original image:

Original Image

Link to image There is download button in lower right

Portion of Python script where I detect contours:

image = cv2.imread("/Users/donaldkeidel/Downloads/input_template_masked.jpg")
# grayscale the image
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
# apply a Gaussian blur
blur = cv2.GaussianBlur(gray, (3, 3), 0)
# threshold the image
(t, binary) = cv2.threshold(blur, 100, 255, cv2.THRESH_BINARY)
# find contours
(_, contours, _) = cv2.findContours(binary, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
image_cropped_contoured_drawn = cv2.drawContours(image.copy(), contours, -1, (0, 255, 0), 3)
cv2.imwrite("F4GSCZQJHG7K_template_masked_contoured_exploration.jpg", image_cropped_contoured_drawn)

Here is the output image:

Contoured Image

Link to image There is download button in lower right

As you can see in the image, almost all the contours were captured where the background color is a lighter gray. However, where the background is an almost black in the middle of the image, less contours were detected.

Is there some techniques that can be applied to detect more of these contours? I played with the threshold value and found that 100 works the best. I also used a few other values for the parameters in the GaussianBlur method.

I could not get my images into this document so I uploaded them and provided links.

Thank you.

background color affecting contour detection

I have been successful in detecting contours and drawing those back on the original image.

Here is my original image:

Original ImageOriginal Image

Link to image There is download button in lower right

Portion of Python script where I detect contours:

image = cv2.imread("/Users/donaldkeidel/Downloads/input_template_masked.jpg")
# grayscale the image
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
# apply a Gaussian blur
blur = cv2.GaussianBlur(gray, (3, 3), 0)
# threshold the image
(t, binary) = cv2.threshold(blur, 100, 255, cv2.THRESH_BINARY)
# find contours
(_, contours, _) = cv2.findContours(binary, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
image_cropped_contoured_drawn = cv2.drawContours(image.copy(), contours, -1, (0, 255, 0), 3)
cv2.imwrite("F4GSCZQJHG7K_template_masked_contoured_exploration.jpg", image_cropped_contoured_drawn)

Here is the output image:

Contoured ImageContoured Image

Link to image There is download button in lower right

As you can see in the image, almost all the contours were captured where the background color is a lighter gray. However, where the background is an almost black in the middle of the image, less contours were detected.

Is there some techniques that can be applied to detect more of these contours? I played with the threshold value and found that 100 works the best. I also used a few other values for the parameters in the GaussianBlur method.

I could not get my images into this document so I uploaded them and provided links.

Thank you.

background color affecting contour detection

I have been successful in detecting contours and drawing those back on the original image.

Here is my original image:

Original ImageOriginal Image

Link to image There is download button in lower right

Portion of Python script where I detect contours:

image = cv2.imread("/Users/donaldkeidel/Downloads/input_template_masked.jpg")
# grayscale the image
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
# apply a Gaussian blur
blur = cv2.GaussianBlur(gray, (3, 3), 0)
# threshold the image
(t, binary) = cv2.threshold(blur, 100, 255, cv2.THRESH_BINARY)
# find contours
(_, contours, _) = cv2.findContours(binary, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
image_cropped_contoured_drawn = cv2.drawContours(image.copy(), contours, -1, (0, 255, 0), 3)
cv2.imwrite("F4GSCZQJHG7K_template_masked_contoured_exploration.jpg", image_cropped_contoured_drawn)

Here is the output image:

Contoured ImageContoured Image

Link to image There is download button in lower right

As you can see in the image, almost all the contours were captured where the background color is a lighter gray. However, where the background is an almost black in the middle of the image, less contours were detected.

Is there some techniques that can be applied to detect more of these contours? I played with the threshold value and found that 100 works the best. I also used a few other values for the parameters in the GaussianBlur method.

I could not get my images into this document so I uploaded them and provided links.

Thank you.

background color affecting contour detection

I have been successful in detecting contours and drawing those back on the original image.

Here is my original image:

Original Image

Link to image There is download button in lower right

Portion of Python script where I detect contours:

image = cv2.imread("/Users/donaldkeidel/Downloads/input_template_masked.jpg")
# grayscale the image
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
# apply a Gaussian blur
blur = cv2.GaussianBlur(gray, (3, 3), 0)
# threshold the image
(t, binary) = cv2.threshold(blur, 100, 255, cv2.THRESH_BINARY)
# find contours
(_, contours, _) = cv2.findContours(binary, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
image_cropped_contoured_drawn = cv2.drawContours(image.copy(), contours, -1, (0, 255, 0), 3)
cv2.imwrite("F4GSCZQJHG7K_template_masked_contoured_exploration.jpg", image_cropped_contoured_drawn)

Here is the output image:

Contoured Image

Link to image There is download button in lower right

As you can see in the image, almost all the contours were captured where the background color is a lighter gray. However, where the background is an almost black in the middle of the image, less contours were detected.

Is there some techniques that can be applied to detect more of these contours? I played with the threshold value and found that 100 works the best. I also used a few other values for the parameters in the GaussianBlur method.

I could not get my images into this document so I uploaded them and provided links.

Thank you.

background color affecting contour detection

I have been successful in detecting contours and drawing those back on the original image.

Here is my original image:

Original ImageOriginal Image

Link to image There is download button in lower right

Portion of Python script where I detect contours:

image = cv2.imread("/Users/donaldkeidel/Downloads/input_template_masked.jpg")
# grayscale the image
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
# apply a Gaussian blur
blur = cv2.GaussianBlur(gray, (3, 3), 0)
# threshold the image
(t, binary) = cv2.threshold(blur, 100, 255, cv2.THRESH_BINARY)
# find contours
(_, contours, _) = cv2.findContours(binary, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
image_cropped_contoured_drawn = cv2.drawContours(image.copy(), contours, -1, (0, 255, 0), 3)
cv2.imwrite("F4GSCZQJHG7K_template_masked_contoured_exploration.jpg", image_cropped_contoured_drawn)

Here is the output image:

Contoured Image

Link to image There is download button in lower right

As you can see in the image, almost all the contours were captured where the background color is a lighter gray. However, where the background is an almost black in the middle of the image, less contours were detected.

Is there some techniques that can be applied to detect more of these contours? I played with the threshold value and found that 100 works the best. I also used a few other values for the parameters in the GaussianBlur method.

I could not get my images into this document so I uploaded them and provided links.

Thank you.

background color affecting contour detection

I have been successful in detecting contours and drawing those back on the original image.

Here is my original image:

Original ImageC:\fakepath\output_template_masked_contoured_exploration_resized.jpg

Link to full size image There is download button in lower right

Portion of Python script where I detect contours:

image = cv2.imread("/Users/donaldkeidel/Downloads/input_template_masked.jpg")
# grayscale the image
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
# apply a Gaussian blur
blur = cv2.GaussianBlur(gray, (3, 3), 0)
# threshold the image
(t, binary) = cv2.threshold(blur, 100, 255, cv2.THRESH_BINARY)
# find contours
(_, contours, _) = cv2.findContours(binary, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
image_cropped_contoured_drawn = cv2.drawContours(image.copy(), contours, -1, (0, 255, 0), 3)
cv2.imwrite("F4GSCZQJHG7K_template_masked_contoured_exploration.jpg", image_cropped_contoured_drawn)

Here is the output image:

Contoured ImageC:\fakepath\input_template_masked_resized.jpg

Link to full size image There is download button in lower right

As you can see in the image, almost all the contours were captured where the background color is a lighter gray. However, where the background is an almost black in the middle of the image, less contours were detected.

Is there some techniques that can be applied to detect more of these contours? I played with the threshold value and found that 100 works the best. I also used a few other values for the parameters in the GaussianBlur method.

I could not get my images into this document so I uploaded them and provided links.

Thank you.

background color affecting contour detection

I have been successful in detecting contours and drawing those back on the original image.

Here is my original image:

C:\fakepath\output_template_masked_contoured_exploration_resized.jpgC:\fakepath\input_template_masked_resized.jpg

Link to full size image There is download button in lower right

Portion of Python script where I detect contours:

image = cv2.imread("/Users/donaldkeidel/Downloads/input_template_masked.jpg")
# grayscale the image
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
# apply a Gaussian blur
blur = cv2.GaussianBlur(gray, (3, 3), 0)
# threshold the image
(t, binary) = cv2.threshold(blur, 100, 255, cv2.THRESH_BINARY)
# find contours
(_, contours, _) = cv2.findContours(binary, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
image_cropped_contoured_drawn = cv2.drawContours(image.copy(), contours, -1, (0, 255, 0), 3)
cv2.imwrite("F4GSCZQJHG7K_template_masked_contoured_exploration.jpg", image_cropped_contoured_drawn)

Here is the output image:

C:\fakepath\input_template_masked_resized.jpgC:\fakepath\output_template_masked_contoured_exploration_resized.jpg

Link to full size image There is download button in lower right

As you can see in the image, almost all the contours were captured where the background color is a lighter gray. However, where the background is an almost black in the middle of the image, less contours were detected.

Is there some techniques that can be applied to detect more of these contours? I played with the threshold value and found that 100 works the best. I also used a few other values for the parameters in the GaussianBlur method.

Thank you.

background color affecting contour detection

I have been successful in detecting contours and drawing those back on the original image.

Here is my original image:

C:\fakepath\input_template_masked_resized.jpgC:\fakepath\input_template_masked_resized.jpg

Link to full size image There is download button in lower right

Portion of Python script where I detect contours:

image = cv2.imread("/Users/donaldkeidel/Downloads/input_template_masked.jpg")
# grayscale the image
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
# apply a Gaussian blur
blur = cv2.GaussianBlur(gray, (3, 3), 0)
# threshold the image
(t, binary) = cv2.threshold(blur, 100, 255, cv2.THRESH_BINARY)
# find contours
(_, contours, _) = cv2.findContours(binary, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
image_cropped_contoured_drawn = cv2.drawContours(image.copy(), contours, -1, (0, 255, 0), 3)
cv2.imwrite("F4GSCZQJHG7K_template_masked_contoured_exploration.jpg", image_cropped_contoured_drawn)

Here is the output image:

C:\fakepath\output_template_masked_contoured_exploration_resized.jpgC:\fakepath\output_template_masked_contoured_exploration_resized.jpg

Link to full size image There is download button in lower right

As you can see in the image, almost all the contours were captured where the background color is a lighter gray. However, where the background is an almost black in the middle of the image, less contours were detected.

Is there some techniques that can be applied to detect more of these contours? I played with the threshold value and found that 100 works the best. I also used a few other values for the parameters in the GaussianBlur method.

Thank you.

background color affecting contour detection

I have been successful in detecting contours and drawing those back on the original image.

Here is my original image:

C:\fakepath\input_template_masked_resized.jpg

Link to full size image There is download button in lower right

Portion of Python script where I detect contours:

image = cv2.imread("/Users/donaldkeidel/Downloads/input_template_masked.jpg")
# grayscale the image
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
# apply a Gaussian blur
blur = cv2.GaussianBlur(gray, (3, 3), 0)
# threshold the image
(t, binary) = cv2.threshold(blur, 100, 255, cv2.THRESH_BINARY)
# find contours
(_, contours, _) = cv2.findContours(binary, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
image_cropped_contoured_drawn = cv2.drawContours(image.copy(), contours, -1, (0, 255, 0), 3)
cv2.imwrite("F4GSCZQJHG7K_template_masked_contoured_exploration.jpg", image_cropped_contoured_drawn)

Here is the output image:

C:\fakepath\output_template_masked_contoured_exploration_resized.jpg

Link to full size image There is download button in lower right

As you can see in the image, almost all the contours were captured where the background color is a lighter gray. However, where the background is an almost black in the middle of the image, less contours were detected.

Is Are there some techniques that can be applied to detect more of these contours? I played with the threshold value and found that 100 works the best. I also used a few other values for the parameters in the GaussianBlur method.

Thank you.

background color affecting contour detection

I have been successful in detecting contours and drawing those back on the original image.

Here is my original image:

C:\fakepath\input_template_masked_resized.jpg

Link to full size image There is download button in lower right

Portion of Python script where I detect contours:

image = cv2.imread("/Users/donaldkeidel/Downloads/input_template_masked.jpg")
# grayscale the image
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
# apply a Gaussian blur
blur = cv2.GaussianBlur(gray, (3, 3), 0)
# threshold the image
(t, binary) = cv2.threshold(blur, 100, 255, cv2.THRESH_BINARY)
# find contours
(_, contours, _) = cv2.findContours(binary, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
image_cropped_contoured_drawn = cv2.drawContours(image.copy(), contours, -1, (0, 255, 0), 3)
cv2.imwrite("F4GSCZQJHG7K_template_masked_contoured_exploration.jpg", image_cropped_contoured_drawn)

Here is the output image:

C:\fakepath\output_template_masked_contoured_exploration_resized.jpg

Link to full size image There is download button in lower right

As you can see in the image, almost all the contours were captured where the background color is a lighter gray. However, where the background is an almost black in the middle of the image, less contours were detected.

Are there some techniques that can be applied to detect more of these contours? I played with the threshold value and found that 100 works the best. I also used a few other values for the parameters in the GaussianBlur method.

Thank you.

Update:

I applied equalizeHist by doing the following:

image = cv2.imread("/Users/donaldkeidel/Downloads/input_template_masked.jpg")
# grayscale the image
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
# Histogram equalization
equ = cv2.equalizeHist(gray)
# threshold the image
(t, binary) = cv2.threshold(equ, 100, 255, cv2.THRESH_BINARY)
# find contours
(_, contours, _) = cv2.findContours(binary, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
image_cropped_contoured_drawn = cv2.drawContours(image.copy(), contours, -1, (0, 255, 0), 3)
cv2.imwrite("F4GSCZQJHG7K_template_masked_contoured_exploration.jpg", image_cropped_contoured_drawn)

The following image shows the gray scale image compared to Histogram Equalized image: C:\fakepath\F4GSCZQJHG7K_template_masked_equalized_hist_exploration_resized.jpg

And here is image after contour detection:

C:\fakepath\F4GSCZQJHG7K_template_masked_contoured_exploration_resized.jpg

Any further suggestions on how to proceed are appreciated. I like the suggestion about increasing the contrast using Histogram Equalizatioon, however, drawing contours on this image proves to be difficult. Should I preprocess the image more?