MATLAB Answers


how to segment hand from an image with non uniform lighting?

Asked by H
on 12 Jul 2014
Latest activity Commented on by Image Analyst
on 14 Jul 2014
I'm trying to segment the hand from the image but due to the non uniform lighting the result come out like this
the result in uniform lighting
how to solve this problem?


Sign in to comment.

3 Answers

Answer by Image Analyst
on 12 Jul 2014
 Accepted Answer

Just fix the lighting - it's so simple! It's almost always easier to prevent the problem than to fix it with software and that is definitely the case here.
If you don't want to get the job done in the most sensible, easy, straightforward, and best way (by fixing the illumination), then there are more complicated ways that you can do it, but you have to make some assumptions, like on the size of the hand, or its color, or on the smoothness of the background, or things like that. Some fix you make for one situation might not work for another. Like if you have that picture and then another where the hand is in front of a flesh colored screen, or a screen with a paisley background - those may all take different algorithms.
For what it's worth, I attach a background correction demo.


Show 1 older comment
It sounds like they're intentionally providing poor images for you to test the robustness of your algorithm. Do they provide an algorithm that works for all their images? If so, use that one. If not you'll have to invent your own algorithm, because we don't do complex algorithm development here, just help with syntax, error messages, program flow, etc. If you don't want to invent your own algorithm, then I suggest you use, or start with, one of the algorithms given here:,%20Detection,%20Tracking,%20Gesture%20Recognition,%20Fingerprints,%20Biometrics
Thanks for your help
If you know your background is always neutral colored and your hands are not, then you can convert to hsv color space and threshold for reddish pixels. See my demo :

Sign in to comment.

Answer by Laila Kazemi on 12 Jul 2014

You need adaptive threshold since the background changes. I have not yet found a good code in matlab for this. you might have to find your own algorithm and code it.

  1 Comment

Here I used graythresh(). but I also tried many different levels for the shareholding other than this level but it didn't work. I also used diifferent segmentation techniques and the result is the same. I think the first step should be fixing the illumination.

Sign in to comment.

Answer by Prasad Kalane on 14 Jul 2014

% Do some image illumination correction.
background = imopen(I,strel('disk',15));
I = I - backgroundbackground
I = imadjust(I);
% level = graythresh(I);
bw = im2bw(I,0.3*level);


Sign in to comment.