Howdy!
I'm building a mobile app via React Native that requires some image processing: I need to determine the percentage of color red splotches on a green colored background. I've done some research already into some other discussions on the ImageMagick discussion archives, but I'm really lost.
There are two main things I need help with:
1. Again, devising a method to extract the percentage of color red splotches covering a green colored background (e.g., "this image is 40% covered with green")
2. How I would go about implementing such a method in my React Native project (javascript).
Image Stipulations:
1. the image will be taken via a smartphone
2. image will not have 1 red rgb value and 1 green rgb value, but rather a range of colors close to red and green on the image (this is a consequence of there will be shading on the image
If you can lead me to any old thread, a specific topic to read on, or anything that would mean the world to me!
Thanks
How to determine percentage of "X" color from "Y" colored background.
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: How to determine percentage of "X" color from "Y" colored background.
Assuming you have only red and green, then change the red to white and the green to black. Then the average lightness of the image is the proportion that were red.
You have to decide what to do about intermediate colours. Perhaps a pixel coloured midway between red and green counts as half a red pixel. Or perhaps this is a binary threshold: every pixel counts as either red or green.
You also need to define "red" and "green". Perhaps they are the colours #f00 and #0f0.
EDIT: If you want sample commands, please tell us the version number of IM you use, and what platform.
You have to decide what to do about intermediate colours. Perhaps a pixel coloured midway between red and green counts as half a red pixel. Or perhaps this is a binary threshold: every pixel counts as either red or green.
You also need to define "red" and "green". Perhaps they are the colours #f00 and #0f0.
EDIT: If you want sample commands, please tell us the version number of IM you use, and what platform.
snibgo's IM pages: im.snibgo.com