How to check for white image backgrounds using RMagick or any other Ruby Gems?
I am trying to validate images based on few criteria:
The image should not have a border [I could accomplish to an extent using RMagick and its 'trim' method.]
The image must have a white background
开发者_如何学编程The image should not contain any visible watermark.
Please let me know if you can think of any way to accomplish #2 and #3 above.
Note: I am using Ruby so any solution using Ruby or Ruby gems is appreciated.
For detecting #1 (not removing), I would read the color of every pixels along the edge and calculate the standard deviation. If it's very low or zero (and the pixels are non-white) then you have a border. Keep doing this in loops from the edge in case there is a multi-pixel-wide border.
For #2 you could look at the four corners of the image and see if they are all white (or maybe 3/4). You could, alternatively, count the number of pixels in the image that are full white and ensure that there are a large number of them.
For #3, I have no idea. You're talking about some seriously advanced image processing. A brief Google search turned up few good answers for detecting common low-opacity/blended watermarks. There are good resources for extracting your own stenography 'watermark' from an image, but I suspect that is not your goal.
精彩评论