in reply to check if image is monochromatic

When many people say "black & white" they really mean "shades of gray". If that's what you mean, and your system has (or you can get) djpeg and ppmhist as suggested by JavaFan, you might then process the @out array to see if all of the color triplets have 3 values "close together" which indicates grayscale. First look at the results of piping these as he suggests "by hand" and see what the the numbers look like.