Loran
Loran

Reputation: 852

Emgu GetAverage Color of black color of Image

I am new at Emgu cv. My target is to compare two photos which are the same photo but the brightness is slightly different and gets the dark color or dark spot percentage of ROI.

I saw GetAverage method but how can I get color percentage of image by specify color. eg black is 80%, white 20%.

What is the mask parameter in the GetAverage method?

I read the documentation but I don't understand.

My idea is I will change both photos to grayscale and set ROI then get the average value. I don't know its the correct way to get my target.

So How can I done this?

Update

Below are ROI images of grayscale.

enter image description here

I add some scratch to the right photo.

enter image description here

Why scratch photo intensity is lower than without scratch photo. By right, It should be greater right? because it have more gray color right? Why?

Or

I added scratch, it means more black, So gray color reduction?

Upvotes: 0

Views: 609

Answers (1)

lorenzozane
lorenzozane

Reputation: 1279

What is the mask parameter in the GetAverage method?

The mask parameter in the overloaded GetAverage(mask) allow you to find the average color of the masked area only according to the official documentation.

Regarding the concept of mask (which is related to the concept of ROI), it allows you to analyze or elaborate (depending on the context) only the location of the image where the mask is non-zero. I invite you to deepen on this here. If you find the documentation not clear enough, try to understand how masks works in Photoshop, the concept is the same and surely you will find many more explanations and much more intuitive.

Why scratch photo intensity is lower than without scratch photo. By right, It should be greater right? because it have more gray color right? Why?

No, it shouldn't be grather. Here as indicated by the documentation, GetAverage() returns to you the average color with the structure you originale image have (TColor), Gray (grayscale) in this case.
As you can see here the grayscale value for darker color tents to 0, on the contrary the white corresponds to 255. So adding scratch implies that your image darkens.
If you try apply GetAverage() to an image with a different color type (Bgr, Bgra, Hsv, Hls, ...), it will return you the average as color of that type.

Last thing,

I saw GetAverage method but how can I get color percentage of image by specify color. eg black is 80%, white 20%.

you cannot with this approach. As said above GetAverage() returns to you a Gray color. The only thing I can suggest is that you manually convert the result obtained into a percentage of color with something like this:

private double ConvertToPercentage(double valueToConvert, int rangeStartAt, int rangeEndAt) {
    return valueToConvert/(rangeEndAt - rangeStartAt) * 100;
}

Obviously this piece of code only works with single values colors (not rgb for example, which has 3 values). You can very easily re-implement something like this in case you need it.

Upvotes: 1

Related Questions