Image subtraction negative pixels rounded to 0
古いコメントを表示
Hi.
I'm doing some background modelling. I have a set of images with the same background but the foreground is changing. I'm taking the median pixels from the set of images to retreive the background and the background extraction is successful.
I am then concatenating the 3 channels for the extracted background as follows:
backgroundImage = uint8(cat(3,median_bg_RedValues,median_bg_GreenValues,median_bg_BlueValues));
However, when I try to do image - backgroundImage, any values that are negative are rounded to 0, resulting in a black background.
How can I take the absolute value of the pixel rather than rounding to 0? (..e:
newimg = abs(image - backgroundImage)
(which doesn't work - all negative values are rounded to 0)
I'm loading the other image as standard:
image = imread('test.jpg')
I've even tried changing uint8 to int8 but I get an error:
Error using - Integers can only be combined with integers of the same class, or scalar doubles.
How can I do this nicely?
Thanks for any help.
採用された回答
その他の回答 (2 件)
Image Analyst
2016 年 2 月 17 日
1 投票
Sounds like what you really need to do is color classification, not subtraction. You could simply call rgb2hsv and look for certain hues. Or call rgb2ind() and tell it to find 4 colors. See my File Exchange for color segmentation demos: http://www.mathworks.com/matlabcentral/fileexchange/?term=authorid%3A31862
Matt J
2016 年 2 月 17 日
newimg = abs(double(image) - double(backgroundImage))
5 件のコメント
Faizan Tahir
2016 年 2 月 17 日
編集済み: Faizan Tahir
2016 年 2 月 17 日
Faizan Tahir
2016 年 2 月 17 日
Image Analyst
2016 年 2 月 17 日
Please attach your image with the green and brown frame icon. Don't make us work blind.
Faizan Tahir
2016 年 2 月 17 日
Image Analyst
2016 年 2 月 17 日
I never use it. I don't like how it scales the range of my images to 0-1. I like to leave the ranges in the original range, not scaled and shifted. I don't know how you're seeing the original colors. A subtraction image will not show original colors. For example a reddish object colored with RGB = [200, 100, 50] and another reddish object at [190,90, 40] will have a difference of [10,10,10] which is dark gray, not red.
カテゴリ
ヘルプ センター および File Exchange で Image Preview and Device Configuration についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!