MATLAB: Changing Blackground of Image to gray

changing background of image!

Hi Guys, I have an jpg / bmp image (3 D) with a black background. Can anybody tell me how can I modify this image to convert black background to gray. I only want to modify the background without changing the picture in between.

Best Answer

if isreal(YourImage)
greycol = 0.5;
else
greycol = intmax(class(YourImage)) / 2;
end
[rows, cols, panes] = size(YourImage);
blacks = find( ~sum(YourImage,3) );
YourImage( [blacks, blacks + rows*cols, blacks + 2*rows*cols]) = greycol;
Related Question