필터 지우기
필터 지우기

can u pls explain this code in detail?

조회 수: 2 (최근 30일)
ASHA
ASHA 2014년 4월 7일
편집: Jan 2014년 4월 7일
clc;
clear all;
close all;
warning off all;
%%Input Image
[f,p] = uigetfile('*.png');
I = imread([p f]);
figure,imshow(I);
title('Input image');
% imhist(I);title('histogram of input image');
I = imresize(I,[256 256]);
a1=rgb2gray(I);
figure,imshow(a1);title('Cropped gray scale image');
%%Smoothing
m = medfilt2(a1);
figure;
%subplot(2,2,1);
imshow(m);title('Median filtered image ');
%subplot(2,2,2);
figure;imhist(m);title('Histogram');
% Enhancing the image
b=imadjust(m);
figure;
%subplot(2,2,1);
imshow(b);title('Enhanced image');
%subplot(2,2,2);
figure;imhist(b);title('Histogram');
%%Denosing using GLPF
%%(1) FFT
% f_transform=fft2(a1);
% f_shift=fftshift(f_transform);
% p=256/2;
% q=256/2;
% d0=35;
% for i=1:256
% for j=1:256
% distance=sqrt((i-128)^2+(j-128)^2);
% low_filter(i,j)=exp(-(distance)^2/(2*(d0^2)));
% end
% end
% %%(2) IFFT
% filter_apply=f_shift.*low_filter;
% image_orignal=ifftshift(filter_apply);
% image_filter_apply=abs(ifft2(image_orignal));
% figure;imshow(image_filter_apply);title('GLPF result in the FFT image');
% hsize = [3 3];
% sigma = 0.5;
% h = fspecial('gaussian', hsize, sigma);
% g = imfilter(a1,h);
% figure;imshow(g);title('GLPF result in the input image');
%%(3) Gaussian & Rayleigh denoising
%%Adding & Removing Gaussian noise
n = imnoise(a1,'gaussian',0.05);
figure;
%subplot(2,2,1);
imshow(n);title('Guassian noisy image');
%subplot(2,2,2);
figure;imhist(n);title('Histogram');
K = wiener2(n,[5 5]);
figure;
%subplot(2,2,1);
imshow(K);title('Gaussian noise removed image');
%subplot(2,2,2);
figure;imhist(K);title('Histogram');
disp('Parameter calculation for Multiplicative Rayleigh Noise removed Image');
%%Parameter Calculation for Gaussian Noise removed Image
%%Signal to signal noise ratio, SNR
noise = double(n) - double(a1);
noisyImageReconstructed = double(a1) + noise;
residue = noisyImageReconstructed - double(n);
if (sum(residue(:) ~= 0))
disp('The noise is NOT relevant.');
end
snr_power = SNR(a1, noise);
fprintf('SNR = %5.5f dB \n', snr_power);
%%PSNR
psnr_Value = PSNR(a1, n);
fprintf('PSNR = %5.5f dB \n', psnr_Value);
%%RMSE
[mse, rmse] = RMSE2(double(a1), double(n));
fprintf('MSE = %5.5f \n', mse);
fprintf('RMSE = %5.5f \n', rmse);
%%Mean absolute error, MAE
mae = meanAbsoluteError(double(a1), double(n));
fprintf('MAE = %5.5f \n', mae);
%%Adding & Removing multiplicative rayleigh noise
sd = 1;
[M,N] = size(a1);
r = imnoise2('rayleigh',M,N,0,1);
% figure;imshow(r),title('Noise to be added');
c = find(r == 1);
gp = a1;
gp(c) = 255;
r = uint8(r);
noisyImage = gp+r;
figure;
%subplot(2,2,1);
imshow(noisyImage),title('Image after adding Multiplicative Rayleigh Noise');
%subplot(2,2,2);
figure;imhist(noisyImage);title('Histogram');
fp = imrest(gp,'chmean',3,3,-5.5);
figure;
%subplot(2,2,1);
imshow(fp),title('Image after removing Multiplicative Rayleigh Noise')
%subplot(2,2,2);
figure;imhist(fp);title('Histogram');
disp(' ')
disp(' ')
disp('Parameter Calculation for Guassian Noise removed Image');
%%Parameter Calculation for Multiplicative Rayleigh Noise removed Image
originalImage = a1;
%%Signal to signal noise ratio, SNR
noise = double(noisyImage) - double(originalImage);
noisyImageReconstructed = double(originalImage) + noise;
residue = noisyImageReconstructed - double(noisyImage);
if (sum(residue(:) ~= 0))
disp('The noise is NOT relevant.');
end
snr_power = SNR(originalImage, noise);
fprintf('SNR = %5.5f dB \n', snr_power);
%%PSNR
psnr_Value = PSNR(originalImage, noisyImage);
fprintf('PSNR = %5.5f dB \n', psnr_Value);
%%RMSE
[mse, rmse] = RMSE2(double(originalImage), double(noisyImage));
fprintf('MSE = %5.5f \n', mse);
fprintf('RMSE = %5.5f \n', rmse);
%%Mean absolute error, MAE
mae = meanAbsoluteError(double(originalImage), double(noisyImage));
fprintf('MAE = %5.5f \n', mae);
%%(4) Binarization
level = graythresh(fp);
BW = im2bw(fp,level);
figure;imshow(BW);title('Otsu binarized image');
%%Image segementation & Edge detection
%%Edge detection
% e = edge(fp,'canny');
% figure,imshow(e);
% title('edge detected in the gray image');
ed = edge(BW,'canny');
figure;imshow(ed);
title('Edge detected in the binarized image');
%%Smoothing
% m = medfilt2(fp);
% figure;imshow(m);title('noise removed image');
%%Gradient
[Gx, Gy] = imgradientxy(m);
[Gmag, Gdir] = imgradient(Gx, Gy);
figure;imshowpair(Gmag, Gdir, 'montage');axis off;
title('Gradient Magnitude and Gradient Direction');
Gmag = max(max(Gmag))
Gdir = max(max(Gdir))
%%Non_Maximum Suppression, Double & Hysteresis thresholding
non_maxSup(m);
%%Feature Extraction
%%Contour Segmentation
figure;
[Im,phi]=region_seg_demo(m,uint8(m));
figure,imshow(Im);
hold on;
contour(phi, [0 0], 'r','LineWidth',2);
colormap gray
hold off;drawnow;
%%Height & Width calculation
BW = Im;
s = regionprops(BW,'MajorAxisLength');
height = s.MajorAxisLength
s1 = regionprops(BW,'MinorAxisLength');
width = s1.MinorAxisLength
%%Neural classiifcation
data = height;
data3_5 = data;
save data3_5 data3_5
%%Simulate the neural network using the data
load net1
y = round(sim(net1,data));
if y == 0
disp('DIASTOLE');
msgbox('DIASTOLE','Result')
elseif y == 1
disp('DIASTOLE');
msgbox('DIASTOLE','Result')
elseif y == 2
disp('SYSTOLE');
msgbox('SYSTOLE','Result')
elseif y == 3
disp('SYSTOLE');
msgbox('SYSTOLE','Result')
end

답변 (2개)

Walter Roberson
Walter Roberson 2014년 4월 7일
How much familiarity with The Calculus are we allowed to assume you have when we undertake to prove the essential theorems this code relies on? Are we allowed to assume that you are quite familiar with the Central Limit Theorem ? Are you familiar with the IEEE 754 standards for floating point arithmetic? Have you worked with binary integer arithmetic before? How much signal theory have you taken? I generally find that it takes students more than two months to really understand SNR, PSNR, and RMSE, but if that's what it takes to explain the code in detail then that's what it takes.

Jan
Jan 2014년 4월 7일
편집: Jan 2014년 4월 7일
Sorry, ASHA, this is a funny question. I'm not able to explain this code in detail. But I start with the 4 first lines at least:
clc;
clear all;
close all;
warning off all;
  1. This hides former messages in the command window. Is this really useful?
  2. It clears all variables, functions, classes and Mex files from the memory and deletes all breakpoints. While reloading the files from the hard disk wastes time, the loss of the breakpoints prevents a successful debugging. Especially if you want to understand the code, stepping through it line by line would be a good idea. So "clear all" is bad.
  3. All other figures are closed.
  4. All useful warning messages are suppressed. This is a really really bad idea.
A code starting with such a brute header is suspicious. This does definitely discourage me to even start to read the rest.
Finally I suggest to ask a specific question. Currently it is not clear, if you need a detailed explanation for [f,p] = uigetfile('*.png') or if this would just waste our and your time.

카테고리

Help CenterFile Exchange에서 Import, Export, and Conversion에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by