I have roughly 400 images of two hands doing gestures. The hands never meet. I need to remove the left hand from the image without changing the resolution or size of the image and basically would need to make the black color the same gray as the background. What are my best options to do so?

Here are four examples of the images I have in my dataset:

silhouette hands

  • That requires computer vision techniques which is imho a little beyond the more or less simple image processing questions that are on topic on Ask Ubuntu. I recommend that you ask your question on Computer Graphics or Stack Overflow. Sep 27, 2017 at 7:52
  • I guess you want to do it automatically. If fully automatic, I have the same suggestion as @DavidFoerster. If you want to do it semi-automatically, maybe you can use imagemagick by manually selecting where to apply the mask (how big fraction of the image to cover from the left edge) to cover the left hand, if enough with one dimension. (You can do it manually with gimp, but with 400 pictures it would be a lot of boring manual operations.)
    – sudodus
    Sep 27, 2017 at 8:11
  • 1
    This question seems OK to me although otoh out of cowardice I asked a somewhat similar question (about GIMP, not ImageMagick) on Graphics Design Stack Exchange instead of here and it got answered there.
    – karel
    Sep 27, 2017 at 8:47
  • @karel: Could you please provide a link to that question? I can't find it in your activity log. Sep 27, 2017 at 9:01
  • Link: graphicdesign.stackexchange.com/questions/67173/… In case this is confusing I'm trying to learn how to automate the process of editing boot screen photos in order to save time when editing these images in GIMP.
    – karel
    Sep 27, 2017 at 9:18

1 Answer 1


I know this question is some days old, but in case someone comes across, I can drop a suggestion on how to solve this:

It indeed takes some computer vision or image processing tasks, but I would do it like this:

  1. At first you could apply some morphological operations (like opening or closing) in order to reduce the spurious black pixels in the background. You have to play around with different combinations of such operations to get what you want.
  2. Then you could compute connected components (= connected regions of pixels belonging together), which basically gives you labels for all pixel regions.
  3. Then you can filter those connected components for the 2 biggest ones (= the ones with the most pixels in it), which will give you the two hand regions only.
  4. Now you can decide - maybe using the x/y-coordinates of the center of each region - which region you want to mask out, e.g. by filling it with the gray-value from the background pixels.

I hope this helps and gives some clues on how to do it.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .