Unrecognized function or variable 'imnoise2'.

조회 수: 18 (최근 30일)
Dimitriy 2023년 3월 19일
답변: Image Analyst 2023년 3월 20일
Initially, I need to denoise the image using the Rayleigh function.
I am working on a lab and when I run the command:
% // Generate Uniform Noise Matrices, Scaled Down by 70%.
UN_R = 0.3 * imnoise2('uniform', 512, 512);
UN_G = 0.3 * imnoise2('uniform', 512, 512);
UN_B = 0.3 * imnoise2('uniform', 512, 512);
As instructed I get the error:
Unrecognized function or variable 'imnoise2'.
Error in noise (line 29)
UN_R = 0.3 * imnoise2('uniform', 512, 512);
Here is all the code used:
%....................................................................
% // Uniform Random Noise in The Range [0, 1] Scaled by k = 0.3. |
% // Rayleigh Noise with its [A = 0, B = 1] Scaled by k = 0.3. |
% // Exponential Noise Scaled By 0.2 Where The Value of A = 1. |
% // Gamma (Erlang) Noise where [A, B ] = [2, 5] and SF 'K' = 0.1. |
% // imnoise2.m File Function Is Called Inside This Program. |
%...................................................................|
%// Read an Image from The Given Path.
% // Extract Red, Green and Blue Channels of Input.
Rframe = img(:, :, 1);
Gframe = img(:, :, 2);
Bframe = img(:, :, 3);
Rframe = double(Rframe);
Gframe = double(Gframe);
Bframe = double(Bframe);
% // Normalized Intensities of Each Channel [0, 1].
Rframe = Rframe - min(Rframe(:));
Rframe = Rframe / max(Rframe(:));
Gframe = Gframe - min(Gframe(:));
Gframe = Gframe / max(Gframe(:));
Bframe = Bframe - min(Bframe(:));
Bframe = Bframe / max(Bframe(:));
% // Generate Uniform Noise Matrices, Scaled Down by 70%.
UN_R = 0.3 * imnoise2('uniform', 512, 512);
UN_G = 0.3 * imnoise2('uniform', 512, 512);
UN_B = 0.3 * imnoise2('uniform', 512, 512);
% // Generate Rayleigh Noise Matrices, Scaled Down by 70%.
RN_R = 0.3 * imnoise2('rayleigh', 512, 512);
RN_G = 0.3 * imnoise2('rayleigh', 512, 512);
RN_B = 0.3 * imnoise2('rayleigh', 512, 512);
% // Generate Exponential Noise Matrices, Scaled Down by 80%.
EN_R = 0.2 * imnoise2('exponential', 512, 512);
EN_G = 0.2 * imnoise2('exponential', 512, 512);
EN_B = 0.2 * imnoise2('exponential', 512, 512);
% // Generate Erlang Noise Matrices, Scaled Down by 90%.
GN_R = 0.1 * imnoise2('erlang', 512, 512);
GN_G = 0.1 * imnoise2('erlang', 512, 512);
GN_B = 0.1 * imnoise2('erlang', 512, 512);
% // Add Uniform Noises to Each Image Channel [R, G, B].
R_UNoisy = Rframe + UN_R;
G_UNoisy = Gframe + UN_G;
B_UNoisy = Bframe + UN_B;
% // Add Rayleigh Noises to Each Image Channel [R, G, B].
R_RNoisy = Rframe + RN_R;
G_RNoisy = Gframe + RN_G;
B_RNoisy = Bframe + RN_B;
% // Add Exponential Noises to Each Image Channel [R, G, B].
R_ENoisy = Rframe + EN_R;
G_ENoisy = Gframe + EN_G;
B_ENoisy = Bframe + EN_B;
% // Add Gamma (Erlang) Noises to Each Image Channel [R, G, B].
R_GNoisy = Rframe + GN_R;
G_GNoisy = Gframe + GN_G;
B_GNoisy = Bframe + GN_B;
% // Construct Noisy Images from The Corresponding Noisy Channels.
Img_UNoisy = cat(3, R_UNoisy, G_UNoisy, B_UNoisy);
Img_RNoisy = cat(3, R_RNoisy, G_RNoisy, B_RNoisy);
Img_ENoisy = cat(3, R_ENoisy, G_ENoisy, B_ENoisy);
Img_GNoisy = cat(3, R_GNoisy, G_GNoisy, B_GNoisy);
% // Display Images
figure
subplot(1, 5, 1), imshow(img), title('Original image')
subplot(1, 5, 2), imshow(Img_UNoisy), title('Noisy image, Noise = Uniform')
subplot(1, 5, 3), imshow(Img_RNoisy), title('Noisy image, Noise = Rayleigh')
subplot(1, 5, 4), imshow(Img_ENoisy), title('Noisy image, Noise = exponential')
subplot(1, 5, 5), imshow(Img_GNoisy), title('Noisy image, Noise = Erlang')
% // Save Images to .bmp files
imwrite(Img_UNoisy,'output/Noise_Uni.bmp');
imwrite(Img_RNoisy,'output/Noise_Ray.bmp');
imwrite(Img_ENoisy,'output/Noise_Exp.bmp');
imwrite(Img_GNoisy,'output/Noise_Ga.bmp');
Any ideas why code is not working?
댓글 수: 2없음 표시없음 숨기기
Dyuman Joshi 2023년 3월 19일
imnoise2 is not an inbuilt function nor a part of any toolbox function.
Do you have a function named imnoise2, which is in the current directory?
Dimitriy 2023년 3월 19일
No, I don't have.

댓글을 달려면 로그인하십시오.

답변 (2개)

John D'Errico 2023년 3월 19일
which imnoise2 -all
We cannot help you to use a function that does not exist as part of MATLAB,
Possibly, the code you are using (since it was clearly not written by you) uses a code called imnoise2 as found on the file exchange. A quick search finds at least two places where it may have come from.
Another is in this next contribution. Possibly they are the same function, as the first link seems to be a complete toolbox.
댓글 수: 2없음 표시없음 숨기기
Dimitriy 2023년 3월 20일
These links did not help me. What do I need in order for this to work?
Dyuman Joshi 2023년 3월 20일
You need to download the file (the file will be downloaded as a zip file) and open/save it in the current directory. Then run the code.

댓글을 달려면 로그인하십시오.

Image Analyst 2023년 3월 20일
Try using the imnoise function of the Image Processing Toolbox instead of imnoise2 (which we don't know what that is).

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Image Processing and Computer Vision에 대해 자세히 알아보기

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by