Page 1

:

AM: 2024200600033 AM: 2024200600069 AM: 2024200600008

1


2


..

1. Matlab 2. matlab 3. 4. Contrast - stretching transformation 5. 5.1 For Matlab

5.2

6. Histogram 6.1 6.2

7.

High Boost Filtreing

7.1 7.2

8. color image processing 9. 10. 11.

.. . ..4 .. .. . . .6 .. . .. ...8 ...... .. .. . 10 . . ...... .. . ..12 . . .... ...13 . .. .13 . ..14 ..... ....14 . .... 17 . . . . 19 ... . ..19 ..... . ...21 . . .. 23 ... . 26 . .. ....28 .. ..30

3


1.

Matlab

image.jpg,

f(

)

:

>> f = imread('image.jpg'); ( . * .jpg)

:

>> imwrite(f,'image2.jpg'); >> imwrite(f, 'image2', 'jpg'); imshow: >>imshow('image.jpg') ; >>imshow(f) ; >> image(f);

: >> new = uint8(f);

(x, y, z)

(pixels)

:

>> [x, y, z] = size(f); >> pixels = x*y; ,

f

4


,

:

>> maxValue = max(f(:)); >> minValue = min(f(:)); >>avgValue = mean(f(:));

round: >>avgValue = round(mean(f(:))); : >>avgValue = floor(mean(f(:))); : >>avgValue = ceil(mean(f(:)));

imfinfo: >> imfinfo('image.jpg')

>> whos f format

imformats

matlab:

>> imformats

: >>f_Gr = rgb2gray(f); (1-0 : black-white)

:

>> f_Log = im2bw(f);

( . .tif

jpeg

tif)

>> f = imread('image.jpg'); >> imwrite(f,'image2.tif');

5


2.

matlab

image.jpg

f

: >>f = imread('image.jpg'); (

)

fp [end] [:,:] RedGreenBlue (RGB)

-pixel

-1

>> fp = f(end:-1:1,:,:); : 1( 768

default), -

2

(257) .

>> fc = f(257:768, 257:768); (

2 pixel)

:

fs

(f),

. >> fs = f(1:2:end,1:2:end,:); « (512)

» [:]

512 plot

. >> plot(f(512,:));.

6


,

2

512 [0-255 ]

7


3.

. )

for loop -

mirrorcheckerboard

>> I = checkerboard(30,4);

%

checkerboard

>> subplot(2,1,1);

%

1

>> imshow(I); >> [x,y] = size(I); >> IM = mirrorcheckerboard(); >> subplot(2,1,2);

%

mirrorcheckerboard

%

1

>> imshow(IM);

%%%%%%%%%%%% Function mirrorcheckerboard( ) %%%%%%%%%%%% function [ mir ] = mirrorcheckerboard() % image mirroring function with for

image = checkerboard(30,4); [x,y,z] = size(image);

%

checkerboard

%

for i = 1:x-1 for j = 1:y-1 mir(i,j) = image(x-i , y-j);

%

-mirror

end end end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

8


)

,

>> I = checkerboard(30,4);

%

>> subplot(2,1,1);

%

>> imshow(I);

%

>> IM = I(:,end :-1:1);

%

>> subplot(2,1,2);

%

>> imshow(IM);

)

,

chekerboard 1 checerboard (mirror image) 2

%

)

For loop,

(mirror image)

.

9


4. Contrast - stretching transformation intrans.m function g = intrans(f, varargin) error(nargchk(2, 4, nargin)) classin = class(f); if strcmp(class(f), 'double') && max(f(:)) > 1 && 2 ~strcmp(varargin{1}, 'log'); f = mat2gray(f); else f = im2double(f); end method = varargin{1}; switch method case 'neg' g = imcomplement(f); case 'log' if length(varargin) == 1 c = 1; elseif length(varargin) == 2 c = varargin{2}; elseif length(varargin) == 3 c = varargin{2}; classin = varargin{3}; else error('Incorrect number of inputs for the log option.') end g = c*(log(1 + double(f))); case 'gamma' if length(varargin) < 2 error('Not enough inputs for the gamma option.') end gam = varargin{2}; g = imadjust(f, [ ], [ ], gam); case 'stretch' if length(varargin) == 1 % Use defaults. m = mean2(f); E = 4.0;

10


elseif length(varargin) == 3 m = varargin{2}; E = varargin{3}; else error('Incorrect number of inputs for the stretch option.') end g = 1./(1 + (m./(f + eps)).^E); otherwise error('Unknown enhancement method.') end

.jpg

g

: >>g= imread('x.jpg'); ( contrast stretching transformation) g1 >> g1 = intrans(g, 'stretch', mean2(im2double(g)), 0.9);

(g)

(g1)

11


5. 5.1

For

NegativeIm, . . matlab

,

NegativeIm.m ,

. :

>> g5 = NegativeIm(' image.jpg' );

FUNCTION function [ negative ] = NegativeIm( original )

A = imread(original); [x, y, z] = size(A);

maxValue = 255;

for i = 1:x

% gia to kokkino xrwma

for j = 1:y

R

% gia to prasino xrwma G

for k = 1:z

% gia to mple xrwma

B

negative(i,j,k) = maxValue - A(i,j,k); % anathesi neas timis end %k end %j end %i

imshow(negative)

end

% emfanisi arnitikis eikonas

% function

12


5.2

Matlab:

matlab .

>>f = imread('image.jpg'); >> g1 = imadjust(f, [0, 1], [1, 0]); >> imshow(g1) H >> g = imcomplement(f); >> imshow(g)

>> g2 = imadjust(f, [0.5, 0.75], [0, 1]); >> imshow(g2)

>> g3 = (f, [], [], 2); >> imshow(g3)

Negative (

) g1,g, g5

13


g2

g3 [gamma = 2]

14


6. Histogram 6.1 >> f = imread('image.jpg');

% diavasma eikonas

>> ff = rgb2gray(f);

% metatropi se gray (monoxrwmi)

>> h = imhist(ff);

% istogramma eikonas

>> subplot(2,2,1);

% dimiourgia xwrou gia sxediagrammata kai energopoihsh tou 1ou

>> imhist(ff) ;

% 1o sxediagramma [istogramma eikonas]

>> subplot(2,2,2);

% dimiourgia xwrou gia sxediagrammata kai energopoihsh tou 2ou

>> h1 = h(1:10:256);

% deigmatolipsia me vima 10 tou h, gia kaliteri efkrinia

>> horz = 1:10:256;

% dimeiourgia xwrou gia to sxediagramma

>> bar(horz, h1)

% 2o sxediagramma me bares

>> axis([0 255 0 16000])

% oriothetisi tou sxediagrammatos

>> set(gca, 'xtick', 0:50:255)

% oriothetisi tou sxediagrammatos

>> set(gca, 'ytick', 0:2000:16000)

% oriothetisi tou sxediagrammatos

>> subplot(2,2,3);

% dimiourgia xwrou gia sxediagrammata kai energopoihsh tou 3ou

>> horz = 1:10:256;

% dimeiourgia xwrou gia to sxediagramma

>> stem(horz, h1, '*')

% 3o sxediagramma [istogramma eikonas] me diakrites times

>> axis([0 255 0 16000])

% oriothetisi tou sxediagrammatos

>> set(gca, 'xtick', [0:50:255])

% oriothetisi tou sxediagrammatos

>> set(gca, 'ytick', [0:2000:16000]) % oriothetisi tou sxediagrammatos >> subplot(2,2,4);

% dimiourgia xwrou gia sxediagrammata kai energopoihsh tou 4ou

>> plot(h)

% 4o sxediagramma [istogramma eikonas] me sinexeis times

>> axis([0 255 0 16000])

% oriothetisi tou sxediagrammatos

>> set(gca, 'xtick', [0:50:255])

% oriothetisi tou sxediagrammatos

>> set(gca, 'ytick', [0:2000:16000])

% oriothetisi tou sxediagrammatos

15


16


6.2

-

. [0-255]

>> f = imread('image3.jpg');

% diavasma eikonas

>> ff = rgb2gray(f);

% metatropi se grayscale (moonoxrwmi)

>> subplot(2,2,1);

% dimiourgia xwrou gia sxediagrammata kai energopoihsh tou (a)

>> imshow(ff)

% emfansi eikonas

>> subplot(2,2,2);

% dimiourgia xwrou gia sxediagrammata kai energopoihsh tou (b)

>> imhist(ff);

% emfansi istogrammatos

>> subplot(2,2,3);

% dimiourgia xwrou gia sxediagrammata kai energopoihsh tou (c)

>> g = histeq(ff);

% sinartisi exisoropisis istogrammatos

>> imshow(g)

% emfansi exisoropimenis eikonas

>> subplot(2,2,4);

% dimiourgia xwrou gia sxediagrammata kai energopoihsh tou (d)

>> imhist(g)

% emfansi exisoropimenou istogrammatos

17


a)

b)

c)

d)

18


7.

High Boost Filtreing

7.1

>> f = imread('moon.tif'); >> w4 = fspecial('laplacian', 0); >> w8 = [1 1 1; 1 -8 1; 1 1 1]; >> f = im2double(f); >> g4 = f - imfilter(f, w4, 'replicate'); >> g8 = f - imfilter(f, w8, 'replicate'); >> imshow(f) >> figure, imshow(g4) >> figure, imshow(g8)

a) Arxiki

b) -4

19


b)

-8

20


7.2

(median filters) . >> f = imread('image5.jpg'); >> f = rgb2gray(f); >> fn = imnoise(f, 'salt & pepper', 0.2); >> gm = medfilt2(fn); >> gms = medfilt2(fn, 'symmetric'); >> figure, imshow(f) >> figure, imshow(fn) >> figure, imshow(gm) >> figure, imshow(gms)

a)

b)

(salt & pepper)

21


c) gm (medfilt2)

d) gms (medfilt2, Symmetric)

median- symmetric

22


8. color image processing RGB rgb red , green

MxNx3 blue

pixel .

rgb

.

>> image_Red = image(:,:,1); >> image_Green = image (:,:,2); >> image_Blue = image (:,:,3);

(Indexed image)

map

rgb

.

23


A.

indexed imsow(X,map). .

B. . rgb.

matlab

load trees

pixel

.

(indexed) 5x5

map

: . >> load trees; >> imshow(X,map);

. >> size(X) ans = 258 350

. >> a = X(10,50); >> map(113,:) ans = 0.6471 0.8078 0.9373

24


. >> i = [1,2,3,4,5;1,2,3,4,5;1,2,3,4,5;1,2,3,4,5;1,2,3,4,5]; >> map1= [0.6471,0.8078,0.9373;0.1324,0.6732,0.2311;0.8726,0.6544,0.2111;0.9877,0.1232,0.1232;0.3211,0. 9765,0.1233]; >> imshow(i,map1);

NTSC Color Space >> rgbimageR=rgbimage(:,:,1); >> rgbimageG=rgbimage(:,:,2); >> rgbimageB=rgbimage(:,:,3);

>> w= fspecial('gaussian'); >> rgbimageR_filtered=imfilter(rgbimageR,w); >> rgbimageG_filtered=imfilter(rgbimageG,w); >> rgbimageB_filtered=imfilter(rgbimageB,w); >> rgbimage_filtered = cat(3,rgbimageR_filtered,rgbimageG_filtered,rgbimageB_filtered); >> imshow(rgbimage_filtered);

sharpen >> lapmask=[1,1,1;1,-8,1;1,1,1]; >> fen = imsubtract(rgbimage,imfilter(rgbimage,lapmask,'replicate')); >> imshow(fen)

25


9.

. 0.jpg

f.

>> f=imread('o.jpg');

Fourier

.

>> F=fft2(f); FFT

.

>> S=fftshift(log(1 + abs(F))); (

,

log

) intrans. >> S=intrans(S, 'stretch', mean2(im2double(f)), 0.9); 26


Fourier

f.

>> imshow(S)

fspecial. >> h=fspecial('sobel')

27


10.

. >> freqz2(h)

fftshift . >> H1=ifftshift(h) >> freqz2(H1)

28


29


11.

xM 1

,

.

1xN 1 x M.

>> a=imread('bw1.bmp'); >> a=~a; >> [n,m]=size(a); >> for i=1:m, horiz(i)=sum(a(i,1:m)); end >> for j=1:m, vert(j)=sum(a(1:n,j)); end

>> imshow(~a);

30


>> figure,bar(horiz);

>> figure,bar(vert);

31


32

matlab  

signal image proccessing... matlab

Read more
Read more
Similar to
Popular now
Just for you