I have a binary image 'image_map' which contains either zeros that represent the background, and ones that represent the object... or vice versa. What I would like to do now is work out whether it is the zeros or ones that represent the background.
Since the background is likely to be more uniform (less detail) I thought to use the standard deviation of all grayscale pixel values that are represented by a 1 (I am using 'image_map' just to provide the correct coordinates). I will then repeat this process for the zeros, and the answer with the lowest standard deviation can be selected as the background... However, the way I have programmed this does not seem to be efficient.
Is there a way to achieve the following without using a FOR loop? The processing time is extremely vast if I try to do this as below:
[pix_y pix_x] = find(image_map == 1);
object1(i) = gray_image(pix_y(i),pix_x(i));
Also, if anyone can think of any better way of doing this (I'm sure there will be some), then I would be very happy to hear your suggestions.