Object segmentation not working for black object











up vote
1
down vote

favorite












I am working on a Python script for object segmentation, using opencv. On some objects, this script already works fine. See for example the image below.



enter image description here



However, my script seems to fail on dark coloured objects:



enter image description here



I don't know why this is since I am pretty new to computer vision. My script for object segmentation looks like this:



import cv2
import imutils

image = cv2.imread(input)
dst = cv2.fastNlMeansDenoisingColored(image, None, 10, 10, 7, 21)
hsv = cv2.cvtColor(dst, cv2.COLOR_BGR2HSV)
h, s, v = cv2.split(hsv)
retval, thresholded = cv2.threshold(s, 0, 255, cv2.THRESH_BINARY+cv2.THRESH_OTSU)
medianFiltered = cv2.medianBlur(thresholded, 5)
cnts = cv2.findContours(medianFiltered,
cv2.RETR_TREE,
cv2.CHAIN_APPROX_SIMPLE)
cnts = cnts[0] if imutils.is_cv2() else cnts[1]


Any suggestions on how I can improve this?










share|improve this question


















  • 2




    well, if you think about it... in HSV colorspace the color black is basically when the V channel is close to 0 (doesn't matter the other two channels much)... and you threshold and use the saturation channel which in this case may be quite low. For filtering black over very light backgrounds, maybe it is easier to threshold a greyscale image? however in that case, maybe the line under the door may be an issue
    – api55
    Nov 19 at 16:34










  • Thank you for your suggestion. I have experimented with filtering a grayscale version of the image a bit. However, the difficulty here was finding a good threshold such that the yellow object would be detected.
    – JNevens
    Nov 19 at 16:45















up vote
1
down vote

favorite












I am working on a Python script for object segmentation, using opencv. On some objects, this script already works fine. See for example the image below.



enter image description here



However, my script seems to fail on dark coloured objects:



enter image description here



I don't know why this is since I am pretty new to computer vision. My script for object segmentation looks like this:



import cv2
import imutils

image = cv2.imread(input)
dst = cv2.fastNlMeansDenoisingColored(image, None, 10, 10, 7, 21)
hsv = cv2.cvtColor(dst, cv2.COLOR_BGR2HSV)
h, s, v = cv2.split(hsv)
retval, thresholded = cv2.threshold(s, 0, 255, cv2.THRESH_BINARY+cv2.THRESH_OTSU)
medianFiltered = cv2.medianBlur(thresholded, 5)
cnts = cv2.findContours(medianFiltered,
cv2.RETR_TREE,
cv2.CHAIN_APPROX_SIMPLE)
cnts = cnts[0] if imutils.is_cv2() else cnts[1]


Any suggestions on how I can improve this?










share|improve this question


















  • 2




    well, if you think about it... in HSV colorspace the color black is basically when the V channel is close to 0 (doesn't matter the other two channels much)... and you threshold and use the saturation channel which in this case may be quite low. For filtering black over very light backgrounds, maybe it is easier to threshold a greyscale image? however in that case, maybe the line under the door may be an issue
    – api55
    Nov 19 at 16:34










  • Thank you for your suggestion. I have experimented with filtering a grayscale version of the image a bit. However, the difficulty here was finding a good threshold such that the yellow object would be detected.
    – JNevens
    Nov 19 at 16:45













up vote
1
down vote

favorite









up vote
1
down vote

favorite











I am working on a Python script for object segmentation, using opencv. On some objects, this script already works fine. See for example the image below.



enter image description here



However, my script seems to fail on dark coloured objects:



enter image description here



I don't know why this is since I am pretty new to computer vision. My script for object segmentation looks like this:



import cv2
import imutils

image = cv2.imread(input)
dst = cv2.fastNlMeansDenoisingColored(image, None, 10, 10, 7, 21)
hsv = cv2.cvtColor(dst, cv2.COLOR_BGR2HSV)
h, s, v = cv2.split(hsv)
retval, thresholded = cv2.threshold(s, 0, 255, cv2.THRESH_BINARY+cv2.THRESH_OTSU)
medianFiltered = cv2.medianBlur(thresholded, 5)
cnts = cv2.findContours(medianFiltered,
cv2.RETR_TREE,
cv2.CHAIN_APPROX_SIMPLE)
cnts = cnts[0] if imutils.is_cv2() else cnts[1]


Any suggestions on how I can improve this?










share|improve this question













I am working on a Python script for object segmentation, using opencv. On some objects, this script already works fine. See for example the image below.



enter image description here



However, my script seems to fail on dark coloured objects:



enter image description here



I don't know why this is since I am pretty new to computer vision. My script for object segmentation looks like this:



import cv2
import imutils

image = cv2.imread(input)
dst = cv2.fastNlMeansDenoisingColored(image, None, 10, 10, 7, 21)
hsv = cv2.cvtColor(dst, cv2.COLOR_BGR2HSV)
h, s, v = cv2.split(hsv)
retval, thresholded = cv2.threshold(s, 0, 255, cv2.THRESH_BINARY+cv2.THRESH_OTSU)
medianFiltered = cv2.medianBlur(thresholded, 5)
cnts = cv2.findContours(medianFiltered,
cv2.RETR_TREE,
cv2.CHAIN_APPROX_SIMPLE)
cnts = cnts[0] if imutils.is_cv2() else cnts[1]


Any suggestions on how I can improve this?







opencv image-segmentation






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 19 at 14:03









JNevens

2,05962451




2,05962451








  • 2




    well, if you think about it... in HSV colorspace the color black is basically when the V channel is close to 0 (doesn't matter the other two channels much)... and you threshold and use the saturation channel which in this case may be quite low. For filtering black over very light backgrounds, maybe it is easier to threshold a greyscale image? however in that case, maybe the line under the door may be an issue
    – api55
    Nov 19 at 16:34










  • Thank you for your suggestion. I have experimented with filtering a grayscale version of the image a bit. However, the difficulty here was finding a good threshold such that the yellow object would be detected.
    – JNevens
    Nov 19 at 16:45














  • 2




    well, if you think about it... in HSV colorspace the color black is basically when the V channel is close to 0 (doesn't matter the other two channels much)... and you threshold and use the saturation channel which in this case may be quite low. For filtering black over very light backgrounds, maybe it is easier to threshold a greyscale image? however in that case, maybe the line under the door may be an issue
    – api55
    Nov 19 at 16:34










  • Thank you for your suggestion. I have experimented with filtering a grayscale version of the image a bit. However, the difficulty here was finding a good threshold such that the yellow object would be detected.
    – JNevens
    Nov 19 at 16:45








2




2




well, if you think about it... in HSV colorspace the color black is basically when the V channel is close to 0 (doesn't matter the other two channels much)... and you threshold and use the saturation channel which in this case may be quite low. For filtering black over very light backgrounds, maybe it is easier to threshold a greyscale image? however in that case, maybe the line under the door may be an issue
– api55
Nov 19 at 16:34




well, if you think about it... in HSV colorspace the color black is basically when the V channel is close to 0 (doesn't matter the other two channels much)... and you threshold and use the saturation channel which in this case may be quite low. For filtering black over very light backgrounds, maybe it is easier to threshold a greyscale image? however in that case, maybe the line under the door may be an issue
– api55
Nov 19 at 16:34












Thank you for your suggestion. I have experimented with filtering a grayscale version of the image a bit. However, the difficulty here was finding a good threshold such that the yellow object would be detected.
– JNevens
Nov 19 at 16:45




Thank you for your suggestion. I have experimented with filtering a grayscale version of the image a bit. However, the difficulty here was finding a good threshold such that the yellow object would be detected.
– JNevens
Nov 19 at 16:45

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53376329%2fobject-segmentation-not-working-for-black-object%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53376329%2fobject-segmentation-not-working-for-black-object%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

404 Error Contact Form 7 ajax form submitting

How to know if a Active Directory user can login interactively

TypeError: fit_transform() missing 1 required positional argument: 'X'