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!