If I set black color as a sample in the custom white balance and then take a picture.The picture has a shade of green color. could you please tell me why?
White balance gets corrected by adjusting the relative intensities of red, green, and blue. The ratios are detected in the sample you provide, and the inverse is multiplied to each pixel to even things out. A proper white balance depends on the accuracy of these ratios.
It's hard to get accurate ratios when you measure near black, because a difference of +/- 1 in any of the values can make a huge difference to the ratio. The difference between 1/2 and 1/3 is .1667, while the difference between 127/128 and 127/129 is only .0077.
This means that the brighter your white balance target is the better, but only to a point. If any of the red, green, or blue components hits the rails and maxes out, the numbers will be off and the ratios will be inaccurate again. The best target for white balance is a light gray.
Because black has red, green and blue channel values near zero.
The white balance takes relative values of the color channels as a reference. For black a little higher noise in one channel drastically distorts the relationships. Example for black: red = 0, green = 1, green/red = 1/0 = infinity. So the relationship between red and green is not defined. Example for gray: red = 128, green = 120, green/red = 0.94 (well defined value).
What you stumbled upon is called UniWB (see https://photo.stackexchange.com/a/2421/32110) and can be used to judge exposure in the luminance histogram more accurately. (when shooting Raw, the WB is only influencing the preview image anyway)
Basically, by taking a black picture as custom WB, the weights for all three colour channels are set to 1.0. Since a typical Bayer pattern contains 2 green pixels (since our eyes are most sensitive to green as well), this results is a green cast in the image.