i get black image danoise when the simulation finish what is the problem in the code ?
clc
clear all
close all
image_org=imread(‘C:UserspcOneDriveDesktopmemoirechapitre 3image for test’,’JPG’);
% Gaussian white noise
X = double(image_org) / 255;
NG = imnoise(X, ‘gaussian’, 0, 0.01);%NG=gaussian noise
figure(1);subplot(231); imshow(image_org);title (‘image org’)
subplot(233); imshow(NG) ; title (‘Gaussian additive noise’)
NG_gray = rgb2gray(NG);
%averaging filter
f_m = fspecial (‘average’, 3)%f_m=averaging filter
NGmoy = imfilter (NG, f_m,’replicate’);
%gaussian filter
f_g = fspecial (‘gaussian’,3,0.8)%f_g=gaussian filter
NGg = imfilter(NG,f_g,’replicate’);
%median filter
NGmed = medfilt2( NG_gray ,[3 3]);
%the show
subplot(234); imshow(NGmoy);title(‘ avraging Filter ‘)
subplot(235); imshow(NGg);title(‘ gaussien Filtre ‘)
subplot(236); imshow(NGmed);title(‘ median Filtre’)
%PSNR
EQMb=mean2((X-NG).^2 );PSNRb=-10*log10(EQMb);
EQMmoy=mean2( (NG-NGmoy).^2 );PSNRmoy=-10*log10(EQMmoy);
EQMg=mean2( (NG-NGg).^2 );PSNRg=-10*log10(EQMg);
EQMmed=mean2( (NG_gray-NGmed).^2 );PSNRmed=-10*log10(EQMmed);
% Resize the original image to match the input size of the CNN
image_resized = imresize(image_org, [299 450]);
% Add Gaussian noise to the original image
X = double(image_resized) / 255;
NG = imnoise(X, ‘gaussian’, 0, 0.03); % Add Gaussian noise
% Display the original and noisy images
figure(1);
subplot(1, 2, 1);
imshow(image_resized);
title(‘Original Image’);
subplot(1, 2, 2);
imshow(NG);
title(‘Noisy Image’);
% Prepare data for training (noisy images as input, original images as target)
inputData = NG; % Noisy images
targetData = X; % Original clean images
% Define the CNN architecture for image denoising
layers = [
imageInputLayer([299 450 3]) % Input layer with the size of the input images
convolution2dLayer(3, 64, ‘Padding’, ‘same’) % Convolutional layer with 64 filters of size 3×3
reluLayer % ReLU activation layer
convolution2dLayer(3, 64, ‘Padding’, ‘same’) % Another convolutional layer
reluLayer % ReLU activation layer
convolution2dLayer(3, 3, ‘Padding’, ‘same’) % Output convolutional layer with 3 channels (RGB)
regressionLayer % Regression layer
];
% Define training options
options = trainingOptions(‘adam’, … % Adam optimizer
‘MaxEpochs’, 50, … % Increase the number of epochs
‘MiniBatchSize’, 16, … % Decrease the mini-batch size
‘InitialLearnRate’, 1e-4, … % Decrease the initial learning rate
‘Plots’, ‘training-progress’); % Plot training progress
% Train the network
net = trainNetwork(inputData, targetData, layers, options);
% Denoise the image using the trained CNN
denoisedImage = predict(net, inputData);
% Display the original noisy image and the denoised image
figure;
subplot(1, 2, 1);
imshow(inputData);
title(‘Noisy Image’);
subplot(1, 2, 2);
imshow(denoisedImage);
title(‘Denoised Image’);clc
clear all
close all
image_org=imread(‘C:UserspcOneDriveDesktopmemoirechapitre 3image for test’,’JPG’);
% Gaussian white noise
X = double(image_org) / 255;
NG = imnoise(X, ‘gaussian’, 0, 0.01);%NG=gaussian noise
figure(1);subplot(231); imshow(image_org);title (‘image org’)
subplot(233); imshow(NG) ; title (‘Gaussian additive noise’)
NG_gray = rgb2gray(NG);
%averaging filter
f_m = fspecial (‘average’, 3)%f_m=averaging filter
NGmoy = imfilter (NG, f_m,’replicate’);
%gaussian filter
f_g = fspecial (‘gaussian’,3,0.8)%f_g=gaussian filter
NGg = imfilter(NG,f_g,’replicate’);
%median filter
NGmed = medfilt2( NG_gray ,[3 3]);
%the show
subplot(234); imshow(NGmoy);title(‘ avraging Filter ‘)
subplot(235); imshow(NGg);title(‘ gaussien Filtre ‘)
subplot(236); imshow(NGmed);title(‘ median Filtre’)
%PSNR
EQMb=mean2((X-NG).^2 );PSNRb=-10*log10(EQMb);
EQMmoy=mean2( (NG-NGmoy).^2 );PSNRmoy=-10*log10(EQMmoy);
EQMg=mean2( (NG-NGg).^2 );PSNRg=-10*log10(EQMg);
EQMmed=mean2( (NG_gray-NGmed).^2 );PSNRmed=-10*log10(EQMmed);
% Resize the original image to match the input size of the CNN
image_resized = imresize(image_org, [299 450]);
% Add Gaussian noise to the original image
X = double(image_resized) / 255;
NG = imnoise(X, ‘gaussian’, 0, 0.03); % Add Gaussian noise
% Display the original and noisy images
figure(1);
subplot(1, 2, 1);
imshow(image_resized);
title(‘Original Image’);
subplot(1, 2, 2);
imshow(NG);
title(‘Noisy Image’);
% Prepare data for training (noisy images as input, original images as target)
inputData = NG; % Noisy images
targetData = X; % Original clean images
% Define the CNN architecture for image denoising
layers = [
imageInputLayer([299 450 3]) % Input layer with the size of the input images
convolution2dLayer(3, 64, ‘Padding’, ‘same’) % Convolutional layer with 64 filters of size 3×3
reluLayer % ReLU activation layer
convolution2dLayer(3, 64, ‘Padding’, ‘same’) % Another convolutional layer
reluLayer % ReLU activation layer
convolution2dLayer(3, 3, ‘Padding’, ‘same’) % Output convolutional layer with 3 channels (RGB)
regressionLayer % Regression layer
];
% Define training options
options = trainingOptions(‘adam’, … % Adam optimizer
‘MaxEpochs’, 50, … % Increase the number of epochs
‘MiniBatchSize’, 16, … % Decrease the mini-batch size
‘InitialLearnRate’, 1e-4, … % Decrease the initial learning rate
‘Plots’, ‘training-progress’); % Plot training progress
% Train the network
net = trainNetwork(inputData, targetData, layers, options);
% Denoise the image using the trained CNN
denoisedImage = predict(net, inputData);
% Display the original noisy image and the denoised image
figure;
subplot(1, 2, 1);
imshow(inputData);
title(‘Noisy Image’);
subplot(1, 2, 2);
imshow(denoisedImage);
title(‘Denoised Image’); clc
clear all
close all
image_org=imread(‘C:UserspcOneDriveDesktopmemoirechapitre 3image for test’,’JPG’);
% Gaussian white noise
X = double(image_org) / 255;
NG = imnoise(X, ‘gaussian’, 0, 0.01);%NG=gaussian noise
figure(1);subplot(231); imshow(image_org);title (‘image org’)
subplot(233); imshow(NG) ; title (‘Gaussian additive noise’)
NG_gray = rgb2gray(NG);
%averaging filter
f_m = fspecial (‘average’, 3)%f_m=averaging filter
NGmoy = imfilter (NG, f_m,’replicate’);
%gaussian filter
f_g = fspecial (‘gaussian’,3,0.8)%f_g=gaussian filter
NGg = imfilter(NG,f_g,’replicate’);
%median filter
NGmed = medfilt2( NG_gray ,[3 3]);
%the show
subplot(234); imshow(NGmoy);title(‘ avraging Filter ‘)
subplot(235); imshow(NGg);title(‘ gaussien Filtre ‘)
subplot(236); imshow(NGmed);title(‘ median Filtre’)
%PSNR
EQMb=mean2((X-NG).^2 );PSNRb=-10*log10(EQMb);
EQMmoy=mean2( (NG-NGmoy).^2 );PSNRmoy=-10*log10(EQMmoy);
EQMg=mean2( (NG-NGg).^2 );PSNRg=-10*log10(EQMg);
EQMmed=mean2( (NG_gray-NGmed).^2 );PSNRmed=-10*log10(EQMmed);
% Resize the original image to match the input size of the CNN
image_resized = imresize(image_org, [299 450]);
% Add Gaussian noise to the original image
X = double(image_resized) / 255;
NG = imnoise(X, ‘gaussian’, 0, 0.03); % Add Gaussian noise
% Display the original and noisy images
figure(1);
subplot(1, 2, 1);
imshow(image_resized);
title(‘Original Image’);
subplot(1, 2, 2);
imshow(NG);
title(‘Noisy Image’);
% Prepare data for training (noisy images as input, original images as target)
inputData = NG; % Noisy images
targetData = X; % Original clean images
% Define the CNN architecture for image denoising
layers = [
imageInputLayer([299 450 3]) % Input layer with the size of the input images
convolution2dLayer(3, 64, ‘Padding’, ‘same’) % Convolutional layer with 64 filters of size 3×3
reluLayer % ReLU activation layer
convolution2dLayer(3, 64, ‘Padding’, ‘same’) % Another convolutional layer
reluLayer % ReLU activation layer
convolution2dLayer(3, 3, ‘Padding’, ‘same’) % Output convolutional layer with 3 channels (RGB)
regressionLayer % Regression layer
];
% Define training options
options = trainingOptions(‘adam’, … % Adam optimizer
‘MaxEpochs’, 50, … % Increase the number of epochs
‘MiniBatchSize’, 16, … % Decrease the mini-batch size
‘InitialLearnRate’, 1e-4, … % Decrease the initial learning rate
‘Plots’, ‘training-progress’); % Plot training progress
% Train the network
net = trainNetwork(inputData, targetData, layers, options);
% Denoise the image using the trained CNN
denoisedImage = predict(net, inputData);
% Display the original noisy image and the denoised image
figure;
subplot(1, 2, 1);
imshow(inputData);
title(‘Noisy Image’);
subplot(1, 2, 2);
imshow(denoisedImage);
title(‘Denoised Image’); deep learning, neural network MATLAB Answers — New Questions