Ask Your Question
0

How to calculate standard deviation on image with transparency

asked 2017-11-10 04:12:21 -0600

Andriezel gravatar image

Hello everyone.

How do I calculate the standard deviation and mean on a certain image with transparency? I tried loading an image and then calculate the stddev and mean but I'm getting unexpected results.

This is my image with transparency: image description

Now, I want to calulate this only on the red star. So how do I do this? Because OpenCV treats transparent as black.

Thanks.

edit retag flag offensive close merge delete

Comments

honestly, try to avoid images with transparency for computer-vision. those were made, to look nice in games or on webpages, but here, you have a problem. (even, if you read it in correctly, using the IMREAD_ANY_COLOR flag)

"I want to calulate this only on the red star." -- not possible. you will always have some border pixels around it

berak gravatar imageberak ( 2017-11-10 04:22:25 -0600 )edit

Thanks Berak! I will try to find another way then.

Andriezel gravatar imageAndriezel ( 2017-11-10 04:56:12 -0600 )edit

it's a bit unclear, what you're trying to achieve here. even if you could avoid the border pixels, using a mask or such, -- the stddev of a monochrome surface is just 0, right ? (remember your last experiment)

so, what is it about ?

berak gravatar imageberak ( 2017-11-10 05:17:00 -0600 )edit
1

well, i want to know the mean color of the object. This is just 1 color, but I have other images which have a lot of different colors in it. For example an image that contains a rose. I segmented the rose out of the image and so I have my blob ready. Now I need stddev and mean calculations which I can use for other things. Now I know that stddev of a monochrome surface is 0. That's why I don't use a mask.

Andriezel gravatar imageAndriezel ( 2017-11-10 06:26:33 -0600 )edit
1

maybe you can sample a small roi inside the star, like:

Mat roi = image(Rect(200,200,10,10)); // i made up the numbers, just to show !
Scalar m,d;
meanStdDev(roi, m, d);
berak gravatar imageberak ( 2017-11-10 06:48:24 -0600 )edit

Yes, I was thinking the same thing. Maybe, because I can find the contour of the star and find the center of that contour and after that create a ROI around the center. I will try! Thanks for your help! :)

Andriezel gravatar imageAndriezel ( 2017-11-10 07:11:15 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
1

answered 2017-11-10 17:32:15 -0600

Tetragramm gravatar image

Both mean and meanStdDev take a mask parameter.

If the transparency layer exists in the image you're reading in, just use extractChannel to pull it out. Make sure to threshold it at some value, since masks only work with 0 and 255. As @berak said, you can read in the images with the transparency in the fourth channel by using the IMREAD_ANY_COLOR or possibly the IMREAD_UNCHANGED flags.

If you just have the segmentation from other processing in OpenCV, it's not really transparency, just use it as a mask.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2017-11-10 04:12:21 -0600

Seen: 4,380 times

Last updated: Nov 10 '17