AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |
Back to Blog
Test print image black and white11/1/2023 ![]() This solution is inspired by TomB's post. If someone has a better approach, let me know. That's why I have another level to note really sure color image from the others. As an example, I have several JPEG images that are view as color but in real are grayscale with some color artefacts due to a scan process. The COLOR and MAYBE_COLOR constant are quick switches to find the differences between color and grayscale images but it is not safe. Is_monochromatic = reduce(lambda x, y: x and y \t', Thanx to this post for the monochromatic determination of an image. I have found a way to guess this with the PIL.ImageStat module. SSE += sum((pixel - mu - bias)*(pixel - mu - bias) for i in ) Thumb = pil_img.resize((thumb_size,thumb_size)) from PIL import Image, ImageStatĭef detect_color_image(file, thumb_size=40, MSE_cutoff=22, adjust_color_bias=True): grayscale images with small color stamps. Maybe looking at median squared error instead of MSE would better allow e.g. Accuracy could probably be further improved by using a nonlinear bias adjustment (color values must be between 0 and 255 for example). I ran this on a test set of 13,000 photographic images and got classification with 99.1% precision and 92.5% recall. You can separate these out from true grayscale by thresholding on the color band means. A side effect of this is that it will also detect monochrome but non-grayscale images (typically sepia-toned stuff, the model seems to break down a little in detecting larger deviations from grayscale). Shrink down the image first so you don't have to process millions of pixels.īy default this function also uses a mean color bias adjustment, which I find improves the prediction. The correct way to do this is to calculate the variance per pixel. I tried Gepeto's solution and it has a lot of false positives since the color grand variances can be similar just by chance.
0 Comments
Read More
Leave a Reply. |