Image subtraction negative pixels rounded to 0
Mostrar comentarios más antiguos
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.
Respuesta aceptada
Más respuestas (2)
Image Analyst
el 17 de Feb. de 2016
1 voto
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
el 17 de Feb. de 2016
newimg = abs(double(image) - double(backgroundImage))
5 comentarios
Faizan Tahir
el 17 de Feb. de 2016
Editada: Faizan Tahir
el 17 de Feb. de 2016
Faizan Tahir
el 17 de Feb. de 2016
Image Analyst
el 17 de Feb. de 2016
Please attach your image with the green and brown frame icon. Don't make us work blind.
Faizan Tahir
el 17 de Feb. de 2016
Image Analyst
el 17 de Feb. de 2016
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.
Categorías
Más información sobre Image Arithmetic en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!