As part of a larger program I need to convert an image to binary and then use the regionprops toolbox to obtain some information from it. All pictures contain one object against a different colored background. However,depending on the color of the object being detected, the object on the binary image turns white while the background turns black or vice versa. In the case where the object turns black the rest of the program gets thrown off.
Is there some way to only obtain an image where the object is in white? As opposed to manually viewing each image and inverting some?
Does your object ever touch edges of the image? If no, check any pixel of the edge, if it's white -> flip the colours.
EDIT: Assuming B is your binary image, add following lines to your code:
B = logical(B); %ensuring it's in "logical" format
if(B(1, 1) == true)
B = ~B;
end;