Image processing 1
At the beginning...
Set files path:
Example 1
Information about an image:
imfinfo( portret.jpg )
Example 2
Spatial coordinates system of the image:
imshow (eye (4)*0.5+0.5,'notruesize')
axis on
grid on
xlabel('columns')
ylabel('rows')
hold on
plot(1:4,1:4,'r','LineWidth',5)
pause(5)
axis xy
Example 3
An artificial 8x8 pixels image resize to the 8 x 7 image dimension using three
different interpolation methods:
L1a=[1 -1 1 -1 1 -1 1 -1];
L1b=[-1;1;-1;1;-1;1;-1;1];
L1=uint8(((L1b*L1a)<0)*255);
figure;
imshow(L1,'notruesize')
pause
[L2a]=imresize(L1,[7 8],'nearest')
figure
imshow(L2a, 'notruesize')
pause
[L2b]=imresize(L1,[7 8],'bilinear')
figure
imshow(L2b, 'notruesize')
pause
[L2c]=imresize(L1,[7 8],'bicubic')
figure
imshow(L2c, 'notruesize')
Exercise 4
Basing on the example above, change a 4x4 chessboard image , in order to
obtain an image with 8x8 dimensions.
Exercise 5
Resize an image portret.jpg using three methods of interpolation. Try to
enlarge and to shrink an image.
You can use scale factor:
L1=imresize(L, scale, method )
... or to specify dimensions of resulting image (can be deformed):
L2=imresize(L, [mrows ncols], method )
Example 6
Image translation with its area increase:
m0=100
n0=160
[L1]=imread('portret.jpg')
figure
imshow(L1)
[m1,n1]=size(L1)
L2=[zeros([m1 n0]),L1;zeros([m0 (n0+n1)])]
figure
imshow(L2)
Example 7
Image translation with its area maintenance:
L1=imread('portret.jpg');
figure;
imshow(L1);
se = translate(strel(1), [100 160]);
L2 = imdilate(L1,se);
figure, imshow(L2)
Exercise 8
Try to translate image an image using different distances.
Example 9
Image rotation by specified angles (positive values counterclockwise,
negative values clockwise) with its area maintenance ('crop'):
L1=imread('portret.jpg');
figure;
imshow(L1);
L2a=imrotate(L1,-60,'crop');
figure;
imshow(L2a);
During rotation new pixels positions appear, so we can specify interpolation
method, as well.
Exercise 10
Rotate an image by another angle (with its area increase).
Exercise 11
Function "fliplr" (flip left-right) image mirror with vertical axis of symmetry,
"flipud" (flip up-down) image mirror using horizontal axis of symmetry.
Try to apply these functions to the image "portret.jpg".
Example 12
Rows or columns adding to the image using "padarray" function (work space
enlargement, rows or columns copying, symmetrical mirror reflection of edge
pad rows/columns.
L1=imread('portret.jpg');
figure;
imshow (L1);
L2a=padarray(L1,[30 80],128,'post');
figure;
imshow (L2a);
L2b=padarray(L1,80,128,'both';)
figure;
imshow (L2b);
L2c=padarray(L1,[80 20],'replicate','both');
figure;
imshow (L2c);
L2d=padarray(L1,30,'symmetric','pre');
figure;
imshow (L2d);
L2e=padarray(L1,[60 60],'symmetric','pre');
figure;
imshow (L2e)
Geometrical distortions
Example13
Function reshape
[L1, map] = imread('portret.jpg');
figure; imshow(L1, map)
[r,c] = size(L1)
L2 = reshape(L1, r*2, c/2);
figure; imshow(L2)
L3 = reshape(L1, r/2, c*2);
figure; imshow(L3)
Example 14
Image distortion using sinus function:
[L1, map] = imread('portret.jpg');
figure; imshow(L1, map)
[r,c] = size(L1)
x = 0:r;
y = round(15*sin(x/5)+16);
L2 = L1;
for i=1:r
L2(i,:) = [L1(i,(c-y(i)):c), L1(i,1:(c-y(i)-1))];
end
figure; imshow(L2)
Example 15
Affine transformations and projections
Affine transformation of plane or space a transformation, in a result is which all the
straight lines remain straight and parallel lines remain parallel, but rectangles become
parallelograms.
Affine transformations include isometry (translation, rotation, axial symmetry, planar
symmetry). Geometric figures properties that do not change during affine
transformations are called affine invariants (i.e. straight lines parallelism).
Affine transformation of plane maintains proportions between parallel lines length,
and affine translation of space proportions between figures area that lie on the
parallel planes.
[L1, map] = imread('portret.jpg');
figure; imshow(L1, map)
tr = maketform('affine', [1 0.5; 0 1; 0 0 ])
L2 = imtransform(L1, tr);
figure; imshow(L2)
tr = maketform('projective', [1 1 0; 0 1 0.001; 0 0.01 1 ])
[L2, x, y] = imtransform(L1, tr);
figure; imshow(x,y,L2)
axis on
Example 16
Polynomial distortions:
[L1, map] = imread('portret.jpg');
figure; imshow(L1, map)
xybase = reshape(randn(12,1),6,2);
tr = cp2tform(xybase, xybase,'polynomial',2)
tr.tdata = [0 0; 1 0; 0 1; 0 0 ;0 0; 0.003 0.003];
L2 = imtransform(L1, tr);
figure; imshow(L2)
axis on
tr.tdata = [0 0; 1 0; 0 1; 0.06 0 ;0.001 0; 0.003 0.003];
L2 = imtransform(L1, tr);
figure; imshow(L2)
axis on
Example 17
Stretching if the image fragments with (or without) its initial dimensions
maintenance.
[L1, map] = imread('portret.jpg');
figure; imshow(L1, map)
axis on
[m,n]=size(L1);
sr = round(size(L1,2)/2);
L1_l = L1(:,1:sr);
L1_r = L1(:,sr+1:end);
L1_rs = imresize(L1_r,[size(L1,1) sr*4]);
L2 = [L1_l L1_rs];
figure; imshow(L2,map); axis on
L2 = imresize(L2, [m n]);
figure; imshow(L2, map); axis on
Wyszukiwarka
Podobne podstrony:
Image processing 4Image processing 62001 12 Gimp Workshop Image ProcessingImage processing 7Image processing 8A Erhardt Ferron Theory and Applications of Digital Image ProcessingImage processing introimageprocesyWyświetlacz MMI z 6 kanałowym procesorem dźwięku (9VD)function pdf execute imageG28 Mirror Imagerup process engineerQCC276Ewięcej podobnych podstron