Digital Image Processing Assignment no. 1
Submitted By:
Syed Hassan Raheem Shah {1412108}
Submitted To: Sir Abdul Khalique
Task 1. Image Writing with extension and quality >> imwrite(f,'gems.jpg','quality',50)
>> imwrite(f,'gems.jpg','quality',25)
>> imwrite(f,'gems.jpg','quality',5)
>> imwrite(f,'gems.jpg','quality',0)
Task 2: conversion of different classes
>> a=2.5 a= 2.5000 >> whos Name a
Size 1x1
Bytes
Class
8
double
Attributes
>> 3/4 ans = 0.7500 >> format long >> 3/4 ans = 0.750000000000000 >> b= rand(3,3) b= 0.814723686393179 0.913375856139019 0.278498218867048 0.905791937075619 0.632359246225410 0.546881519204984 0.126986816293506 0.097540404999410 0.957506835434298 >> x=3.2+4.5i x= 3.200000000000000 + 4.500000000000000i >> format short >> x=3.2+4.5i x= 3.2000 + 4.5000i
>> ClassName = class(object)
ClassName =
double
>> matrix = class(object)
matrix =
double
>> obj = class(s,'matrix') Undefined function or variable 's'.
>> whos Name
Size
Bytes
Class
matrix
1x6
12
char
object
3x3
72
double
Attributes
Task 3: conversion of different types images
1
RGB to Gray
>> RGB=imread('1.jpg','jpg');
>> RGBtoGray=rgb2gray(RGB); >>imshow(RGBtoGray);
2
GGBtoIndex
>> I1=imread('1.jpg'); >> imshow(I1);
>> [any,nothing]=rgb2ind(I1, 10); >> imshow(any,nothing);
Sample is PNG >> imread('AbeCX.PNG')
>> imwrite(sample,'AbeCX.bmp') >> imwrite(sample,'AbeCX.tif') >> imwrite(sample,'AbeCX.jpg')
Task 4: Logical Functions >> f=false(3,3) f= 3×3 logical array 0 0 0 0 0 0 0 0 0 >> t=true(3,3) t= 3×3 logical array 1 1 1 1 1 1 1 1 1 OR Function >> X = [1 0 0 1 1]; >> Y = [0 0 0 0 0]; >> any(X) || any(Y) ans = logical
1
And Function >> any(X) && any(Y) ans = logical
0
Not Function on Identity Matrix >> A=eye(4) A= 1
0
0
0
0
1
0
0
0
0
1
0
0
0
0
1
>> B=~A B = 4×4 logical array
0 1 1 1 1 0 1 1 1 1 0 1 1 1 1 0 Exclusive OR Logical Function >> c=xor(A,B) c= 4×4 logical array 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Islogical Logical Function >> islogical = islogical(A) islogical = logical 0
Task 5:
Vector Indexing
Unit Spaced Vector >>X=1:10 Vector With specified increment >> x=0:0.1:1 x= Columns 1 through 6 0 0.1000 0.2000 0.3000 0.4000 0.5000 Columns 7 through 11
0.6000 0.7000 0.8000 0.9000 1.0000
>> y= 10:-2:0
y= 10
8
6
4
2
0
Index Matrix Row and Colmns >>A=magic(3) A= 3x3 8
1
6
3
5
7
4
9
2
>> A(1,:) For Accessing 1st row ans = 8
1
6
>> A(:,2:3) For Accessing 2nd & 3rd Columns ans = 1
6
5
7
9
2
>> A(:) For Reshape the matrix into column ans = 8 3 4 1 5 9 6 7 2
Task 5: Size Function
>> [x,y]=size(i)
x=
3603
y=
14418
>> [height,width,dim] = size(i) height =
3603
width =
4806
dim
3
=
>> [height,width,colour_planes] = size(i) height =
3603
width =
4806
colour_planes =
3
>> whos Name
Size
Bytes
Class
colour_planes
1x1
8
double
dim
1x1
8
double
height
1x1
8
double
i
3603x4806x3
width
1x1
8
double
x
1x1
8
double
51948054
Attributes
uint8
y
1x1
8
Task 8: Plot Function
Create an x-array of 100 samples between 0 and 4π. >> x=linspace(0,4*pi,100); >> y=sin(x); >> plot(y)
double
Task 9: Rand function 1 dimensional Random Function >> A=rand A=
0.7431
2 dimensional Random Function >> B=rand(5) B= 0.3922 0.6555 0.1712 0.7060 0.0318
0.2769 0.0462 0.0971 0.8235 0.6948
0.3171 0.9502 0.0344 0.4387 0.3816
0.7655 0.7952 0.1869 0.4898 0.4456
3 dimensional Random Function >> C=rand([2,3,2]) C(:,:,1) = 0.6551 0.1190 0.9597 0.1626 0.4984 0.3404 C(:,:,2) = 0.5853 0.7513 0.5060 0.2238 0.2551 0.6991
0.6463 0.7094 0.7547 0.2760 0.6797
Task 10:
A. Imadd() >> I1=imread('1.jpg'); >> imshow(I1)
>>add=imadd(I1,I2) >> imshow(add);
B. imsubtract() >> sub=imsubtract(I1,I2); >> subI=imshow(sub);
>> I2=imread('2.jpg'); >> imshow(I2)
C. immultiply() >> mul=immultiply(I1,I2); >> imshow(mul);
D. imdivide()
>> div=imdivide(I1,I2); >> imshow(div);
E. imabsdiff() >> dif=imabsdiff(I1,I2); >> imshow(dif);
F. imcomplement() >> com=imcomplement(I1);
>> imshow(I1);
G. imlincomb() >> lin=imlincomb(1.5,I1); >> imshow(lin)
Task 11: Logical function { iscell(), iscellstr(), ischar(), isempty(), isequal(), isfield(),isfinite().
A. iscell()
Find the Values are in Array or Not
>> A{1,1} = [ 2 4 6; 1 3 9; 9 8 7; ]; >> A= iscell(A); >> disp(A); True
1 >> b=10; >> c=iscell(B);
>> c=iscell(b); >> disp(c); False
0 B. iscellstr()
>> s='Hellow'; >> iscellstr(s); >> disp(s); Hellow >> str = iscellstr(s); >> disp(str); False
0 C. ischar()
>> z=('A'); >> y=ischar(z); >> disp(y); 1 >> z=('Asdf');
True
>> y=ischar(z); >> disp(y); 0
False
D. isempty() >> A(:,:,:) =[]; >> B=isempty(A); >> disp(B); 1
True
>> A=rand(2,2,2); >> B=isempty(A); >> disp(B); 0
False
E. isequal() >> a=45; >> b=45; >> z=isequal(a,b); >> disp(z); True
1
>> a=45; >> b=40; >> z=isequal(a,b); >> disp(z); 0
False
F. isfield() >> B=struct ('one',1,'tow',2); >> fields = isfield(B,{'two','pi','One',3.14}) fields = 1×4 logical array 0 0 0 0
>> disp(fields); 0 0 0 0 G. isfinite() >> A=1./[-2 -1 0 1 2] A=
-0.5000 -1.0000
>> Fin=isfinite(A); >> disp(Fin); 1 1 0 1 1
Inf
1.0000
0.5000
Task 12: Function imadjust() and imtrans().
A. Imadjust() imadjust(image,[low_in high_in],[low_out high_out],gamma)
>> adjlow=imadjust(I1,[0.3 0.7],[]); >> imshow(adjlow); >>
B. imtransform()
>>I1=imread('1.jpg'); >> trans = maketform('affine',[1 0 0; .5 1 0; 0 0 1]); >> transf= imtransform(I1,trans); >> imshow(I1), figure, imshow(transf);