Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
There are many methods for this. One is "GrowCut Segmentation", which needs my process module, and a swipe mask. Here, I made the swipe mask in Gimp.
The swipe mask, mainMsk.png:
%IMDEV%convert ^
main.jpg ^
( +clone ^
mainMsk.png -process growcut ^
-alpha off ^
-fill Black -opaque Lime ^
-fill White -opaque Red ^
) ^
-alpha off ^
-compose CopyOpacity -composite ^
main_only.png
If you have a large number of similar photos (the hand in different positions), you could use data from the manual swipe mask to make all the others automatically.
Instead of manually creating a swipe mask, we can make it automatically, by specifying a pair of rectangles: one at the hand, and another at a ceiling tile. This gives the result:
The script for this is slightly complex. It works in HC space (HCL, with L set to constant 50%). It makes a map of average colours in the user-specified rectangles, plus a gray to represent the transitions. It remaps to those colours (with no dithering). It does a "-connected-components", keeping the two largest components, making the rest transparent. It dilates the transparent areas with disk:3. The result is the swipe mask for GrowCut, as above.
Here is another approach. Measure the skin color at some point on the hand that is representative of the proper hue. Convert the color and extract the hue. Then convert the image to extract the hue and threshold on each side of the hue, since it is close to 360. The hue is about 97% so threshold at 90 and above. And at 10% and below to get a mask and use the mask to isolate the hand in the original. Adjust the 90% and 10% as desired to get a better isolation.
Unfortunately, hue=0 is red, but also cannot be distinguished from black/gray/white where the saturation is near zero. So you should create other masks to remove the black and the white (or near zero saturation). But that may remove part of the hand which is very dark, if the threshold is not very low.