code
I = imread('Image.png');
subplot(2, 2, 1),
imshow(I)
title("Original image");
% adding salt and pepper noise
s = imnoise(I, "salt & pepper", 0.20);
subplot(2, 2, 2),
imshow(s);
title("Salt and Pepper noise");
I am trying to add the noise to a grayscale image by using imnoise function, but getting the inputparse error. The error is:
Error in imnoise>ParseInputs (line 114)
a = im2double(a);
Error in imnoise (line 86)
[a, code, classIn, classChanged, p3, p4] = ParseInputs(args{:});
Error in noise (line 7)
s = imnoise(I, "salt & pepper", 0.20);
kindly help please.
thanks in advance

답변 (1개)

DGM
DGM 2023년 2월 3일

0 개 추천

We know that imread() will only return an array of class 'logical', 'uint8', or 'uint16' when given a PNG image. Since only a single output is specified, the array can only be MxNx1 or MxNx3.
If the array were class 'logical', imnoise() would throw an error during input validation, so it wouldn't even make it to line 114.
If the array were 'uint8' or 'uint16', either one should be able to be handled by im2double() without issue, regardless of whether it's single-channel or RGB.
So that leaves us to conclude that either im2double() is missing, corrupted/modified, or shadowed by some user-defined function. I suspect that in any case, there would have been more error messages that weren't included, but that's moot now.
If you think im2double() is being shadowed, check to see.
which im2double -all
/MATLAB/toolbox/matlab/images/im2double.m /MATLAB/toolbox/matlab/bigdata/@tall/im2double.m % tall method /MATLAB/toolbox/parallel/gpu/@gpuArray/im2double.m % gpuArray method /MATLAB/toolbox/parallel/parallel/@codistributed/im2double.m % codistributed method
If you see user-defined functions there, rename them. If images/im2double.m is missing, then you'll have to find out why. Im2double() used to be part of IPT, but regardless of version, if you have imnoise(), you should have im2double().

카테고리

도움말 센터File Exchange에서 Read, Write, and Modify Image에 대해 자세히 알아보기

제품

릴리스

R2018a

질문:

2021년 6월 9일

답변:

DGM
2023년 2월 3일

Community Treasure Hunt

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

Start Hunting!

Translated by