value of Z in in the program doesn't take above 255?? program used for edge detection('salt & pepper nois'e)

value of Z cannot take any value above 255 why?
PROGRAM
for i = 1:imageHeight - windowHeight + 1
for j = 1:imageWidth - windowWidth + 1
window = I(i:i + windowHeight - 1, j:j + windowWidth - 1);
d=window(2,2);
if(window(2,2)~=0 && window(2,2)~=255)
a=0;
for m=1:3
for p=1:3
if(m~=2 || p~=2)
if(window(m,p)~=0 && window(m,p)~=255)
a=a+1
else
end
else
end
end
end
z=a*d
[EDITED, Jan, please format your code properly to make it readable]

Réponses (2)

The program is most likely designed to work on uint8 data - that data is in the range [0, 255] for 2^8 data values.

1 commentaire

I did reload this thread before I've answered, but I did not see your almost equivalent answer. Strange.
There is no varaible called "Z" in your code. I guess you mean the lower case "z".
window = I(...)
d = window(2, 2);
z = a * d;
When "I" is an UINT8 array, and a is a DOUBLE, the multiplication replies the type with the highest restrictions. Therefore the class of z is UINT8 also, which saturates at 255. Test this:
class(z)
You can try:
z = a * double(d);

Cette question est clôturée.

Produits

Question posée :

le 18 Mar 2013

Clôturé :

le 20 Août 2021

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by