Info

This question is closed. Reopen it to edit or answer.

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

1 view (last 30 days)
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]

Answers (2)

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

Jan
Jan on 18 Mar 2013
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);

Products

Community Treasure Hunt

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

Start Hunting!