Posts

Showing posts from May, 2012

Example for simple function with two parameters in matlab

%Let us discuss the function with two paramaters with simple example %We know the formula for the volume of a cone is p*(1/3)*r^2*h conevolmain.m clc; clear all; radius = input('Enter the radus of the cone:'); height = input('Enter the height of the cone:'); cv=conevol(radius,height); fprintf('Volume of the cone with radius %.1f \n and with height %.1f', radius,height); fprintf('\n is:  %.2f'\n,cv); conevol.m function out=conevol(radius,height) out=(pi/3)*radius^2*height; end output: Enter the radus of the cone:5.6 Enter the height of the cone:6 Volume of the cone with radius 5.6  and with height 6.0  is:  197.04

Example for the simple function in Matlab

%Let us discuss functions in Matlab with the simple example % We know the formula for area of the circle is a=pi * r^2. %Let  us write a function for this. areacircmain.m clc; clear all; radius = input('Enter the radus of the circle:'); ac=areacir(radius); fprintf('Area of the circle with radius %.1f is %.1f\n', radius,ac); areacir.m function out=areacir(radius) out=pi*radius^2; end output: Enter the radus of the circle:5.2 Area of the circle with radius 5.2 is 84.9

To find the MSE value

%Let me explain with the same example. %To the input image Iimg applied the 'Salt & Pepper noise' with the noise ratio of 20% and named as 'Nimg'. %Now for the 'Nimg' i applied median filter and named as Mimg. %Now i need to find the 'Mean Square Error' MSE comparison between Mimg and Nimg. clear all close all clc; Iimg=imread('moon.tif'); [r c]=size(  Iimg ); d=ndims( Iimg ); if d == 3      Iimg =rgb2gray( Iimg ); end Iimg=double( Iimg ); Iimg= Iimg /225; Nimg=imnoise( Iimg ,'salt & pepper',0.2); Mimg=medfilt2( Nimg ,[5 5]); clc; Diff= Nimg - Mimg ; MSE= sum(sum(Diff.* Diff)) / (r * c); fprintf('\n\nThe Mse value is:  %d',MSE1); subplot(1,2,1);imshow( Nimg );title('Noised image'); subplot(1,2,2);imshow( Mimg );title('Denoised image'); RESULT: The Mse value is:  2.521604e-002 i.e, MSE ~ 0.0252

To find the PSNR Value for the denoised image

Image
%Let me explain with an example. %To the input image Iimg applied the 'Salt & Pepper noise' with the noise ratio of 20% and named as 'Nimg'. %Now for the 'Nimg' i applied median filter and named as Mimg. %Now i need to find the 'Peak signal noise ratio' PSNR comparison between Mimg and Nimg. clear all close all clc; Iimg =imread('Moon.tif'); [r c]=size( Iimg  ); d=ndims( Iimg  ); if d == 3      Iimg  =rgb2gray( Iimg  ); end Iimg =double( Iimg  ); Iimg = Iimg  /225; Nimg=imnoise( Iimg   ,'salt & pepper',0.2); Mimg =medfilt2( Nimg ,[5 5]); imshow( Mimg  ); clc; fprintf('\n\n###  The PSNR value  ###\n\n') PSNR( Nimg , Mimg  ); subplot(1,2,1);imshow(Nimg);title('Noised image'); subplot(1,2,2);imshow(Mimg);title('Denoised image'); Moon.tif: RESULT: ###  The PSNR value  ### PSNR = +11.21 dB

Matlab code to get negative of an image

Image
clear all; clc; close all; OriImg=imread('lena.tif'); %This will reads the image to i NegImg=imcomplement(OriImg); %This will moves complement of image i into y %The below statements will produce the output subplot(1,2,1);imshow(OriImg);title('Original image'); subplot(1,2,2);imshow(NegImg);title('Negative image'); RESULT: