the problem about use nlfilter
1 view (last 30 days)
Show older comments
Hello, everyone
to imitate the demo from help and the demo from mathworks, I wrote the code about nlfilter.
%a gray level image using nlfilter function
A=imread('C:\Users\yanghang\Pictures\0.jpg');% get the image dimension
[rows,columns,numofColorBands]=size(A);
if numofColorBands >1 %not the gray image
grayimage=A(:,:,2) %Take Green channel
end
fun=@(x)median(x(:));% tell nlfilter to use function median to do its operation
doubleImage=im2double(grayimage);
B=nlfilter(grayimage,[3,3],fun); % filtering the image
subplot(1,3,1);
imshow(A);
subplot(1,3,2);
imshow(grayimage);
subplot(1,3,3);
imshow(B);
There is one thing troubles me. if I replace the first sentence with the second sentence
% doubleImage=im2double(grayimage);
doubleImage=double(grayimage);
I get two results. But in the workplace, the format is all double ,so why there are different?
Thanks in advance.
Hang Yang
0 Comments
Accepted Answer
Walter Roberson
on 14 Sep 2017
() is approximately
function result = im2double(MATRIX)
if isinteger(MATRIX)
result = double(MATRIX) ./ intmax(class(MATRIX));
else
result = double(MATRIX);
end
end
(except a little more complicated for some more cases.)
That is, a uint8 image can have values 0, 1, 2, 3, ... 255. If you double() that then you would get 0.0, 1.0, 2.0, 3.0, ... 255.0 -- double precision numbers but large. However, images that are floating point need to be in the range 0.0 to 1.0, with 0.0 corresponding to minimum and 1.0 corresponding to maximum. To get from 0.0, 1.0, 2.0, 3.0, ... 255.0 to 0.0 to 1.0, you need to divide by 255.0, which is the maximum representable uint8 value.
More Answers (0)
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!