i get black image danoise when the simulation finish what is the problem in the code ?
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
clc
clear all
close all
image_org=imread('C:\Users\pc\OneDrive\Desktop\memoire\chapitre 3\image 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 3x3
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');
2 comentarios
Josh
el 8 de Mayo de 2024
might want to return to this line:
denoisedImage = predict(net, inputData);
the output of predict() will not be an image as your code assumes it to be:
you're probably getting a black image for denoisedImage because it's being handled like a BW or boolean image after predict() outputs something different than what you're expecting
Respuestas (1)
Drishti
el 16 de Sept. de 2024
Hi Nassim,
The issue of black denoised image you are encountering can be resolved by setting the ‘Normalization’ parameter as ‘none’ in the ‘imageInputLayer’ function.
Setting normalization as ‘none’ will allow the network to utilize the critical information present in the original data.
Use the following code snippet to set the normalization parameter as 'none':
imageInputLayer([299 450 3], 'Normalization', 'none')
Furthermore, I have attached the output denoised image below, received after modifying the provided code on sample image:
For better understanding, you can refer to the MATLAB documentation of the imageInputLayer function:
I hope this resolves the issue.
0 comentarios
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!