Clc; Clear ; Close all ; Img 0 = imread ( ‘ rice . png ‘ ) ; Alpha 1 = 0 ; W1 = fspecial ( ‘ laplacian ‘ , alpha 1 ) ; Img 1 = imfilter ( img 0 , w1 , ‘ circular ‘ ) ; Alpha 2 = 0 . 2 ; W2 = fspecial ( ‘ laplacian ‘ , alpha 2 ) ; Img 2 = imfilter ( img 0 , w2 , ‘ circular ‘ ) ; Alpha 3 = 0 . 4 ; W3 = fspecial ( ‘ laplacian ‘ , alpha 3 ) ; Img 3 = imfilter ( img 0 , w3 , ‘ circular ‘ ) ; Alpha 4 = 0 . 8 ; W4 = fspecial ( ‘ laplacian ‘ , alpha 4 ) ; Img 4 = imfilter ( img 0 , w4 , ‘ circular ‘ ) ; Alpha5= 1 ; W5 = fspecial ( ‘ laplacian ‘ , alpha 5 ) ; Img 5 = imfilter ( img 0 , w5 , ‘ circular ‘ ) ; Figure ; Subplot (2, 3 , 1 ) ; Imshow ( img 0 ) ; Title ( ‘ Original Image ‘ ) ; Subplot (2, 3 , 2 ) ; Imshow ( img 1 ) ; Title ( [ ‘ Laplacian with / alpha = num 2 str(alpha 1 ) ] ) ; Subplot (2, 3 ,3) ; Imshow ( img 2 ) ; Title ( [ ‘ Laplacian with \ alpha = num 2 str(alpha 2 ) ] ) ; Subplot (2, 3 , 4) ; Imshow ( img 3 ) ; Title ( [ ‘ Laplacian with\ alpha = num 2 str(alpha 3 ) ] ) ; Subplot (2, 3 , 5) ; Imshow ( img 4 ) ; Title ( [ ‘ Laplacian with \ alpha = num 2 str(alpha 4 ) ] ) ; Subplot (2, 3 ,6) ; Imshow ( img 5 ) ; Title ( [ ‘ Laplacian with\alpha = num 2 str(alpha5) ] ) ;
Functhon Xn = Normalize ( X , beta )
If nargin < 2 Beta = 1 ; End X min = min ( x ( : ) ) ; X max = max ( x ( : ) ) ; XN = ( ( X – X min ) / ( X max – X min ) ) . ^ beta ;
Clc; Clear ; Close all ; Img 0 = imread ( ‘ rice . png ‘ ) ; Img 0 = im2double ( img 0 ) ; Alpha = 0 ; W = fspecial ( ‘ laplacian ‘ , alpha ) ; Img 1 = imfilter ( img 0 , w , ‘ circular ‘ ) ; C = -1 ; Img 2 = img 0 + c * img 1 ; Figure ; Subplot ( 1 , 3 , 1 ) ; Imshow ( img 0 ) ; Title ( ‘ Original Image ‘ ) ; Subplot ( 1 , 3 , 2) ; Imshow ( img 1 ) ; Title ([ ‘ Laplacian with \ alpha = ‘ num2str ( alpha) ] ) ; Subplot ( 1 , 3 , 3 ) ; Imshow ( img 2 ) ; Title ( ‘ Image Enhancement with Laplacian ‘ ) ;
Clc; Clear ; Close all ; Img 1 = imread ( ‘ rice . png ‘ ) ; Sigma = 1 ; W = fspecial ( ‘ Log ‘ , 5 , sigma ); >> w = fspecial ( ‘ Log ‘ , 100 ) ; >> w = w / max ( w ( : ) ) ; >> imshow ( w )
>> w = Normalize ( w ) ; >> imshow ( w )
Clc; Clear ; Close all ; Img 0 = imread ( ‘ rice . png ‘ ) ; Img 0 = im2double ( img 0 ) ; W = fspecial ( ‘ motion ‘ , 40 , 45 ) ; Img = imfilter ( img 0 , w ,’circular ‘ ) ; Figure ; Subplot ( 1 , 2,1) ; Imshow ( img 0 ) ; Title ( ‘ Original Image ‘) ; Subplot ( 1 , 2,2) ; Imshow ( img 1 ) ; Title ( ‘ After Motion Filter ‘ ) ;
>> w = fspecial ( ‘ prewitt ‘ ) W = 1 1 1 0 0 0 -1 -1 -1 >> w = fspecial ( ‘ sobel ‘ ) W = 1 2 1 0 0 0 -1 -2 -1 Clc; Clear ; Close all ; Img 0 = imread ( ‘ rice . png ‘ ) ; Img 0 = im2double ( img 0 ) ; Wp = fspecial ( ‘ prewitt ‘ ) ; Img 1= imfilter ( img 0 , wp ,’circular ‘ ) ; Ws = fspecial ( ‘ Sobel ‘ ) ; Img 2= imfilter ( img 0 , ws ,’circular ‘ ) ; Figure ; Subplot ( 1 , 3, 1) ; Imshow ( img 0 ) ; Title ( ‘ Original Image ‘) ; Subplot ( 1 , 3,2) ; Imshow ( img 1 ) ; Title ( ‘ After Prewitt Filter ‘ ) ; Subplot ( 1 , 3,3) ; Imshow ( img 2 ) ; Title ( ‘ After Sobel Filter ‘ ) ;
Clc; Clear ; Close all ; Img 0 = imread ( ‘ rice . png ‘ ) ; Img 0 = im2double ( img 0 ) ; Wp = fspecial ( ‘ prewitt ‘ ) ; Img 1= imfilter ( img 0 , wp ,’circular ‘ ) ; Img 2= imfilter ( img 0 , wp ,’circular ‘ ) ; Alpha = 0 . 3 ; Img 3= imfilter ( img 0 , alpha *wp + ( 1 – alpha ) * wp ‘ , ‘circular ‘ ) ; Ws = fspecial ( ‘ Sobel ‘ ) ; Img 4= imfilter ( img 0 , ws ,’circular ‘ ) ; Img 5= imfilter ( img 0 , ws ,’circular ‘ ) ; Figure ; Subplot (2, 3, 1) ; Imshow ( img 0 ) ; Title ( ‘ Original Image ‘) ; Subplot (2, 3,2) ; Imshow ( img 1 ) ; Title ( ‘ After H Prewitt Filter ‘ ) ; Subplot (2, 3,3) ; Imshow ( img 2 ) ; Title ( ‘ After V Prewitt Filter ‘ ) ; Subplot (2, 3,4) ; Imshow ( img 3 ) ; Title ( ‘ After Mixed HV Prewitt Filter ‘ ) ; Subplot (2, 3,5 ) ; Imshow ( img 4 ) ; Title ( ‘ After H Sobel Filter ‘ ) ; Subplot (2, 3,6 ) ; Imshow ( img 5 ) ; Title ( ‘ After V Sobel Filter ‘ ) ;
Clc; Clear ; Close all ; Img 0 = imread ( ‘ rice . png ‘ ) ; Img 0 = im2double ( img 0 ) ; Alpha = 0 ; W = fspecial ( ‘unsharp‘ , alpha ) ; Img 1= imfilter ( img 0 , w ,’circular ‘ ) ; Figure ; Subplot (1, 2 , 1) ; Imshow ( img 0 ) ; Title ( ‘ Original Image ‘) ; Subplot (1, 2,2) ; Imshow ( img 1 ) ; Title ( ‘ After Unsharp Filter ‘ ) ;
Clc; Clear ; Close all ; Img 0 = imread ( ‘ rice . png ‘ ) ; Img 0 = im2double ( img 0 ) ; Wp = fspecial ( ‘ prewitt ‘ ) ; Img 1= imfilter ( img 0 , wp ,’circular ‘ ) ; Img 2= imfilter ( img 0 , wp ,’circular ‘ ) ; % Alpha = 0 . 5; % img 3 = imfilter ( img 0 , alpha * wp + ( 1 – alpha ) * wp ‘ , ‘ circular ‘ ) ; Img 3= sqrt ( img 1 . ^ 2 + img 2 . ^ 2 ) ; Ws = fspecial ( ‘ Sobel ‘ ) ; Img 4= imfilter ( img 0 , ws ,’circular ‘ ) ; Img 5= imfilter ( img 0 , ws ,’circular ‘ ) ; Figure ; Subplot (2, 3, 1) ; Imshow ( img 0 ) ; Title ( ‘ Original Image ‘) ; Subplot (2, 3,2) ; Imshow ( img 1 ) ; Title ( ‘ After H Prewitt Filter ‘ ) ; Subplot (2, 3,3) ; Imshow ( img 2 ) ; Title ( ‘ After V Prewitt Filter ‘ ) ; Subplot (2, 3,4) ; Imshow ( img 3 ) ; Title ( ‘ After Mixed HV Prewitt Filter ‘ ) ; Subplot (2, 3,5 ) ; Imshow ( img 4 ) ; Title ( ‘ After H Sobel Filter ‘ ) ; Subplot (2, 3,6 ) ; Imshow ( img 5 ) ; Title ( ‘ After V Sobel Filter ‘ ) ;
Clc; Clear ; Close all ; Img 0 = imread ( ‘ rice . png ‘ ) ; Img 0 = im2double ( img 0 ) ; M = 5 ; N = 3 ; Domain = ones ( M , N ) ; Img 1 = ordfilt 2 ( img 0 , M * N , Domain ) ; Figure ; Subplot ( 1 , 2 , 1 ) ; Imshow ( img 0 ) ; Title ( ‘ Original Image ‘) ; Subplot ( 1 , 2 , 2) ; Imshow ( img 1 ) ; Title ( ‘ After Order Filter ‘ ) ;
Img 1 = ordfilt 2 ( img 0 , 0 , Domain ) ;
Img 1 = ordfilt 2 ( img 0 , ( M * N + 1 ) / 2 , Domain ) ;
Clc; Clear ; Close all ; Img 0 = imread ( ‘ rice . png ‘ ) ; Img 0 = im2double ( img 0 ) ; M = 5 ; N = 3 ; Domain = ones ( M , N ) ; Img 1 = ordfilt 2 ( img 0 ,( M * N + 1 ) / 2 , Domain ) ; Img 2 = imnoise ( img 0 , ‘ salt & pepper ‘ ) ; Img 3 = ordfilt 2 ( img 2 , ( M * N + 1 ) / 2 , Domain ) ; Figure ; Subplot (2 , 2 , 1 ) ; Imshow ( img 0 ) ; Title ( ‘ Original Image ‘) ; Subplot (2, 2 , 2) ; Imshow ( img 1 ) ; Title ( ‘ After Order Filter ‘ ) ; Subplot (2 , 2 , 3) ; Imshow ( img 2 ) ; Title ( ‘ Noisy Image ‘) ; Subplot (2, 2 ,4) ; Imshow ( img 3 ) ; Title ( ‘Noisy Image After Order Filter ‘ ) ;
M = 5 ; N = 5 ; Img 1 = Medfilt 2 ( img 0 , [ M N] ) ; Img 2 = imnoise ( img 0 , ‘ salt & pepper ‘ ) ; Img 3 = medfilt 2 ( img 2 , [M N ] ) ;
I = imread ( ‘ eight . tif ‘ ) ; J = imnoise ( I , ‘ salt & pepper ‘ , 0 . 02 ) ; Figure , imshow ( I ) Figure , imshow ( J )
ادامه در مبحث 7