blm-instagram-bot
blm-instagram-bot copied to clipboard
TODO: Detection method for black photos
Currently the logic checks if all pixels in all channels are below 20.
How well is this working? If it's fine, keep it.
If you want to do something else, here are some suggestions based on my experience with image processing:
Take the average pixel value across all channels. Threshold it to <5. That way, even small blips of white that may be there will get washed out in the process of averaging. From what I understand, having a single pixel of (255,255,255) right now would prevent the logic from returning True (I'm not native to JS but that's my understanding from the cloudfunction repo's index.js
).
Take the median. Same logic.
Sum all three channels, divide by 3. If the proportion of pixels below (5,5,5) exceeds 95% / 99%, mark it as solid.
JPEG compression really in theory shouldn't be leaving artifacts in all-black images. But if someone clips just a bit of white in there, we want to be able to catch that.
colors.getColor() gets the most dominant color as described in colorthief api
Get the dominant color from an image
const colorThief = new ColorThief();
colorThief.getColor(sourceImage);
so it should be fine, heres a test i did with this image (left a little white in the bottom) and it returned rgb value [4, 4, 4]
all the js code does is check that every rgb value in the returned "dominantColor" is under 50 and if it is, it then returns true
cool. It seems to be working fine then. Should probably remove it from To-Do.
I noticed it commented on a IG Live video instead of a regular photo post, so something there didn't go quite right. Otherwise I think the current logic should suffice to close this issue. =)
I'm actually getting comments back from people who wrote messages in white text on black backgrounds. Sometimes a one-liner. In one case, a notepad in dark mode (so, really dark but not black). Another case, a grayscale photo that definitely should not have gotten picked up: https://www.instagram.com/p/CA8nr89J8sd/?igshid=hq56fev9636g
so we may want to tighten the tolerance a bit.
somehow this got picked up... white background! https://www.instagram.com/p/CA8nr-BJn6D/?igshid=104davupcz3cj
https://www.instagram.com/p/CA8nr-BJn6D/?igshid=104davupcz3cj this returned as 44 44 44 https://www.instagram.com/p/CA8nr89J8sd/?igshid=hq56fev9636g this returned as 40, 38, 39
yea thats a problem...
I don't think dominant color is the right metric here. I think a sampling-based approach is better. I.e. take 500 points at random x,y coords across the image, and return true if >75% of them are dark. If you take the smallest image from the image_versions2 array that might help avoid sampling issues, and help perf too. I'm happy to work on this if it's still in JS.
I don't think dominant color is the right metric here. I think a sampling-based approach is better. I.e. take 500 points at random x,y coords across the image, and return true if >75% of them are dark. If you take the smallest image from the image_versions2 array that might help avoid sampling issues, and help perf too. I'm happy to work on this if it's still in JS.
It is! Feel free to check out the cloud function https://github.com/char/blm-cloud-function