Java

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 48

G.

VENKATASWAMY NAIDU COLLEGE (SFC)


(Re-Accredited with ‘A’ Grade by
NAAC) (An Autonomous Institution)
KOVILPATTI-628502
Record of Advanced Java Programming Practical work in

I M. Sc (Information Technology)
Register No: _
Subject code:

This is certified to be the Bonafide Record of the work done by


Of I M.Sc. (Information Technology).

STAFF IN CHARGE HEAD OF THE DEPARTMENT

Submitted for the practical examination held on__________________________at


G. Venkataswamy Naidu College, Kovilpatti.

PLACE: KOVILPATTI EXTERNAL EXAMINERS


DATE: 1.

2.
INDEX

S. No Date Content Page No Signature


1 Read and display the images

Implement the image arithmetic


2 operations
3 Implement image logical operations

4 Geometric Transformation of images

5 Histogram Equalization

6 Non-linear filtering

7 Edge Detection using operators

8 2D DFT and DCT

9 Filtering in frequency domains

10 Conversion between color spaces

11 DWT of images

12 Segmentation
Ex no: 1
Date: Read and Display digital images

Aim:
To read and display digital images using matlab

Algorithm:
 Open a MATLAB application
 Read the image using imread() function
 Plot the images and given the title
 Show the image using imshow() function
 Save the file using .m extension
 Run the file output will be display result.Thus the program was verified and the output
was verified.
Program Coding:
I=imread('C:\Users\PGCSLAB02\Desktop\mat lab images\nature.jpg');
subplot(2,2,1);imshow(I);subimage(I);title('Image 1');
I=imread('C:\Users\PGCSLAB02\Desktop\mat lab images\white.jpg');
subplot(2,2,2);imshow(I);subimage(I);title('Image 2');
I=imread('C:\Users\PGCSLAB02\Desktop\mat lab images\butterfly.jpg');
subplot(2,2,3);imshow(I);subimage(I);title('Image 3');
I=imread('C:\Users\PGCSLAB02\Desktop\mat lab images\bird.jpg');
subplot(2,2,4);imshow(I);subimage(I);title('Image 4');
Output:
Ex no:2
Result:
Thus the program was executed successfully and the output was verified.
Date: Implement the image arithmetic operation

Aim:
To perform arithmetic operation on image

Algorithm:
 Open MATLAB application
 Read the two images using imread() function.
 To perform arthimetic operations images must be in the same size
 Perform resize using resize() function
 Perform arithmetic operations and display the images
 Save the file using .m extension.
Program Coding:
clear all;
close all;
clc;
I1=imread('C:\Users\PGCSLAB02\Desktop\mat lab images\emoji.jpg');
I2=imread('C:\Users\PGCSLAB02\Desktop\mat lab images\smiley.jpg');
[r,c,z]=size(I2);
I1r=imresize(I1,[r,c]);
A=I1r+I2;
B=I2-I1r;
C=I1r.*I2;
D=I2.\I1r;
figure
subplot(231);
imshow(I1r);
subplot(232);
imshow(I2);
subplot(233);
imshow(A);
subplot(234);
imshow(B);
subplot(235);
imshow(C);
subplot(236);
imshow(D);
output
Result:

Thus the program was executed successfully and the output was verified
Ex no:3

Date: Implement image logical operations

Aim:

To perform logical operations on images

Algorithm:

 Open a MATLAB application


 Resize the image to perform using the corresponding function such as bit and() etc.
 Plot the value and give the title
 Save the file using .m extension
 Run the file and output will be displayed.
Program coding:
clear ;
close all;
clc;
i1=imread('C:\Users\PGCSLAB02\Desktop\mat lab images\singam.jpg');
i2=imread('C:\Users\PGCSLAB02\Desktop\mat lab images\logo.jpg');
[r,c,z]=size(i2);
i1r=imresize(i1,[r,c]);
AND=bitand(i1r,i2);
OR=bitxor(i1r,i2);
OR1=bitor(i1r,i2);
COM=imcomplement(i2);
figure
subplot(321);
imshow(i1r);
title('Image 1');
subplot(322);
imshow(i2);
title('Image 2');
subplot(323);
imshow(AND);
title('And operation');
subplot(324);
imshow(OR);
title('Xor operation');
subplot(325);
imshow(OR1);
title('Or operation');
subplot(326);
imshow(COM);
title('Complement of Image 2');
Output:

Result:

Thus the program was executed successfully and the output was verified.
Ex no:4

Date: Geometric transformation of images

Aim:

To perform gemotric transformation of image using matlab

Algorithm:

 Open a MATLAB application


 Read the image using imread() function
 Plot the image and give the title
 Scaling the image using imresize() function
 Rotate the image using imrotate () function
 Save the file using .m extension
 Run the file and output will be display.
Program coding:
clc;
clear all;
%Scaling
I=imread('C:\Users\PGCSLAB02\Desktop\mat lab images\rain1.jpg');
subplot(2,2,1); subimage(I); title('Original Image');
s=input('Enter Scaling Factor'); j=imresize(I,s);
subplot(2,2,2); subimage(j); title('Scaled Image');
%Rotation
K=imrotate(j,60);
subplot(2,2,3); imshow(K); title('Rotated Image 60deg');
R=imrotate(j,45);
subplot(2,2,4); imshow(R); title('Rotated Image 45deg');
Output:

Result:
Thus the program was executed successfully and the output was
verified.
Ex no:5

Date: Histogram Equalization

Aim:

To perform histogram equalization of image in MATLAB

Algorithm:

 Open a MATLAB application


 Read the image using imread() function
 Plot the image and give the title
 Change the original image into gray scale image
 Adjust the image using imadjust() function
 Draw the histogram equalization graph of the image using histeq
 Show the images using imshow()
 Save the file using imshow()
 Run the file and output will be displayed.
Program Coding:
clc;
clear all;
%Image Enhancement
I=imread('C:\Users\PGCSLAB02\Desktop\mat lab images\himalaya.jpg');
subplot(4,2,1);imshow(I);title('Original Image');
g=rgb2gray(I);
subplot(4,2,5);imshow(g);title('Gray Image');
J=imadjust(g,[0.3 0.7],[]);
subplot(4,2,3);imshow(J);title('Enhancement Image');
D=imadjust(I,[0.2 0.3 0;0.6 0.7 1],[]);
subplot(4,2,4);imshow(D);title('Enhancement Image ');
%Histogram and Histogram Equalization
subplot(4,2,7);imhist(g);title('Histogram of Gray Image');
m=histeq(g);
subplot(4,2,6);imshow(m);title('Equalised Image');
subplot(4,2,8);imhist(m);title('Histogram of Equalised Image');
Output:

Result:
Thus the program was executed successfully and the output was
verified.
Ex no:6

Date: Non-linear Filtering

Aim:

To perform a non-linear filtering on images

Algorithm:

 Open the MATLAB application


 Read the image using imread() function
 Use imf, ims ime variable to perform various filter an images
 Use imr, N variable to perform range filter and noise on images
 Perform red, blue and green channels on images
 Give the variable F to concatenate the images. use cat function for concatenation.
 Plot the values for images on subplot() function and give title for the images
 Save and run the program
Program Coding:
i=imread('C:\Users\PGCSLAB02\Desktop\mat lab images\birds.jpg');
%create a normalised 5-by-5 pixels averaging filter
h=ones(5,5)/25;
imf=imfilter(i,h);
ims=stdfilt(i);
ime=entropyfilt(i);
i1=imread('C:\Users\PGCSLAB02\Desktop\mat lab images\rose.jpg');
imr=rangefilt(i1);
i2=imread('C:\Users\PGCSLAB02\Desktop\mat lab images\leaf.jpg');
N=imnoise(i2,'salt & pepper',0.2);
red_channel=N(:,:,1);
green_channel=N(:,:,2);
blue_channel=N(:,:,3);
red_channel=medfilt2(red_channel,[3,3]);
green_channel=medfilt2(green_channel,[3,3]);
blue_channel=medfilt2(blue_channel,[3,3]);
F=cat(3,red_channel,green_channel,blue_channel);
subplot(3,3,1),imshow(i),title('Original Image i');
subplot(3,3,2),imshow(imf),title('Using imfilter');
subplot(3,3,3),imshow(ims,[]),title('Using Standard');
subplot(3,3,4),imshow(ime),title('Entropy');
subplot(3,3,5),imshow(i1),title('Original image i1');
subplot(3,3,6),imshow(imr),title('Using Range');
subplot(3,3,7),imshow(i2),title('Original Image i2');
subplot(3,3,8),imshow(N),title('Salt and pepper image');
subplot(3,3,9),imshow(F),title('Using Median');
Output:

Result:
Thus the program was executed successfully and the output was
verified
Ex no:7
Edge detection using a operator
Date:

Aim:

To perform edge detection of image using operation in MATLAB

Algorithm:

 Open a MATLAB application


 Read the image using imread() function
 Plot the size and give the title
 Change the original image to gray image
 Filter the image using imfilter() function
 Show all the image using imshow() function
 Save the file using .m extension
 Run the file and output will be displayed.
Program Coding:
i=imread('C:\Users\PGCSLAB02\Desktop\mat lab images\logo1.jpg');
subplot(4,2,1),imshow(i),title('Original Image');
g=rgb2gray(i);
subplot(4,2,2),imshow(g),title('Gray Image');
f=fspecial('laplacian',0.05);
im=imfilter(g,f);
subplot(4,2,3),imshow(im),title('Laplacian');
s=edge(g, 'sobel');
subplot(4,2,4),imshow(s),title('Sobel');
p=edge(g, 'prewitt');
subplot(4,2,5),imshow(p),title('Prewitt');
r=edge(g, 'roberts');
subplot(4,2,6),imshow(r),title('Roberts');
[BW,thresh,gv,gh]=edge(g,'sobel',[],'horizontal');
[BW1,thresh1,gv1,gh1]=edge(g,'sobel ',[],'vertical');
subplot(4,2,7),imshow(BW);title('Sobel Horizontal'),subplot(4,2,8);
imshow(BW1),title('Sobel vertical');
Output:

Result:

Thus the program was executed successfully and the output was verified
Ex no:8

Date: 2D DFT and DCT

2D- DFT
2D-DFT

Aim:

To inform 2D discrets fourier in MATLAB

Algorithm:

 Open a MATLAB application


 Read the image using imread() function
 Perfrom fourier tranfrom shifting using fftshift() function
 Also perform inverse fourier transfrom using ifft()
 Now display the images using imshow() function

2D-DCT

Aim:

To inform 2D discrete cosine transfrom in MATLAB

Algorithm:

 Open a MATLAB application


 Calculate DCT and inverse fourier transform using ifft()
 Convert the RGB to gray using rgb2gray() function
 Plot the value subplot() function
 Save the file and run
Program Coding:

2D-DFT
i=imread('C:\Users\PGCSLAB02\Desktop\mat lab images\baby.jpg');
i1=fft2(i);
i2=fftshift(i1);
i3=ifft(i2);
subplot(2,2,1),imshow(i),title('Original Image');
subplot(2,2,2),imshow(i1),title('Fourier Image');
subplot(2,2,3),imshow(i2),title('Shifted Fourier Image');
subplot(2,2,4),imshow(uint8(i3)),title('Inverse Fourier Image');

2D-DCT
RGB=imread('D:\MATLAB RAMYA\pictures\brd1.jpg');
I=rgb2gray(RGB);
J=dct2(I);
J(abs(J)<10)=0;
K=idct2(J);
subplot(2,2,1),imshow(RGB),title('Original Image');
subplot(2,2,2),imshow(I),title('Grayscale image');
subplot(2,2,3),imshow(log(abs(J)),[]),colormap(jet),colorbar,title('Colorbar for discrete
cosine transform');
subplot(2,2,4),imshow(K,[0 255]),title('Inverse discrete cosine');
Result:
Thus the program was executed successfully and the output was verified
Ex no:9

Date: Filtering in frequency domains

Aim:

To perform filtering in frequency domain of the images

Algorithm:

 Open a MATLAB application


 Read the image using imread function
 Use imf() fuction to filter the images
 Use imf function to find the standard filter
 Use ime for entropy filter and imr for range filter
 Use the variable N for finding the noise distortion for the image
 Use color channels for the image
 Use the variable F to concate all the filters
 Plot the function values using subplot() function
 Show the image using imshow() function and give the title
 Display the result
Program Coding:
clc;
clear all;
%Loading Image
im=double(rgb2gray(imread('C:\Users\PGCSLAB02\Desktop\white.jpg')));
F_u_v=fft2(im);
F_u_v=(fftshift(F_u_v));
figure(1);
subplot(1,2,1);imshow(uint8(im));
title('Original Image');
temp=log(abs(F_u_v));
subplot(1,2,2);
imshow(temp,[]);
title('Fourier Spectra');
%Idle Lowpass Filter
%Creating Transfer Function
[M,N]=size(im);
%set up range of variables.
u=0:(M-1);
v=0:(N-1);
%compute the indices for use in meshgrid
idx=find(u>M/2);
u(idx)=u(idx)-M;
idy=find(v>N/2);
v(idy)=v(idy)-N;
%compute the meshgrid arrays.
[V,U]=meshgrid(v,u);
%compute the distances D(U,V).
D0=30;
D=sqrt(U.^2+V.^2);
H=ifftshift(double(D <=D0));
%Applying the transfer function
g=real(ifft2(H.*F_u_v));
%crop to original size.
%g=g(1:size(F_u_v,1),1:size(F_u_v,2));
figure(2);
subplot(1,2,1);imshow(uint8(abs(g)));
title('Filtered Image');
subplot(1,2,2);imshow(H,[]);
title('Idle Lowpass Filter');
%%Gaussian filter
Hg=ifftshift(exp(-(D.^2)./(2*(D0^2))));
%Applying Gaussian Filter
g=real(ifft2(Hg.*F_u_v));
figure(3);
subplot(1,2,1);imshow(uint8(abs(g)));
title('Filtered Image');
subplot(1,2,2);imshow(Hg,[]);
title('Gaussian Lowpass Filter');
%%Idle Highpass Filter
D0=10;
H=ifftshift(double(D<=D0));
Hp=1-H;
%Applying Highpass filter
g=real(ifft2(Hp.*F_u_v));
figure(4);
subplot(1,2,1);imshow(uint8(abs(g)));
title('Filtered Image');
subplot(1,2,2);imshow(Hp,[]);
title('Idle Highpass Filter');
%%Gaussian Highpass Filter
D0=10;
H=ifftshift(exp(-(D.^2)./(2*(D0^2))));
Hgh=1-H;
g=real(ifft2(Hgh.*F_u_v));
figure(5);
subplot(1,2,1);imshow(uint8(abs(g)));
title('Filtered Image');
subplot(1,2,2);imshow(Hgh,[]);
title('Gaussian Highpass Filter');
Output:
Result:
Thus the program was executed successfully and the output was
verified.
Ex no:10

Date: Conversion between color spaces

Aim:

To convert images various between color spaces

Algorithm:

 Open a MATLAB application using imread()


 Read the image and plot the image
 Original image change into ycbcr,ntsc,hsv format
 Show the every image save the file
 Click the run option m. extension
Program Coding:
i=imread('C:\Users\PGCSLAB02\Desktop\mat lab images\image1.jpg');
i2=rgb2ycbcr(i);
i3=rgb2ntsc(i);
i4=rgb2hsv(i);
subplot(2,2,1),imshow(i),title('Original Image');
subplot(2,2,2),imshow(i2),title('YCBCR Image');
subplot(2,2,3),imshow(i3),title('NTSC Image');
subplot(2,2,4),imshow(i4),title('HSV Image');
Output:

Result:

Thus the program was executed successfully and the output was verified
Ex no:11
DWT of Images
Date:

Aim:

To perform discrete wavelet transformation of images in matlab

Algorithm:

 Open a MATLAB application


 Read the image using imread() function
 Filter the images using various techniques such as imfilter(),stdfilt() and entropyflit()
method
 Read another image and perform filtering using rangefilt() technique
 Take another image and add noise using imnoise() function and the colour in to three
colour channels, then perform filtering using media filter medfilt2()
 Now display all the images using imshow()
 Save the file using m. extension.
Program Coding:
clc;
clear all;
close all;
figure(1)
i=imread('C:\Users\PGCSLAB02\Desktop\mat lab images\building.jpg');
imshow(i);
sx=size(i);
[LL,LH,HL,HH]=dwt2(i,'db1');
figure(2)
subplot(2,2,1);imshow(uint8(LL));title('LL band of image');
subplot(2,2,2);imshow(uint8(LH));title('LH band of image');
subplot(2,2,3);imshow(uint8(HL));title('HL band of image');
subplot(2,2,4);imshow(uint8(HH));title('HH band of image');
Output:
Result:
Thus the program was executed successfully and the output was
verified
Ex no:12

Date: segmentation

Aim:

To perform image segmentation using MATLAB

Algorithm:

 Open a MATLAB application


 Read the image perform fourier transform,shift using fft2() and fftshift()
 Display the output and input
 Then calculate the fourier spectum and also display it
 Create transfer function and meshgrid arrays
 Apply craussian filtering and highpass filtering of the image
 Display the result using imshow() function
 Save the file using .m extension
 Run the file.
Program Coding:
he=imread('C:\Users\PGCSLAB02\Desktop\mat lab images\whiteblood.jpg');
figure(1);
imshow(he),title('H&E Image');
text(size(he,2),size(he,1)+15,...
'Image Courtesy of Alan Partin, Johns Hopkins University',...
'Fontsize',7,'HorizontalAlignment','right');
form = makecform('srgb2lab');
lab_he = applycform(he,form);
ab = double(lab_he(:,:,2:3));
nrows = size(ab,1);
ncols = size(ab,2);
ab = reshape(ab,nrows*ncols,2);
nColors = 3;
%repeat the clustering 3 times to avoid local minims
[cluster_idx, cluster_center] = kmeans (ab,nColors,'distance','sqEuclidean',...
'Replicates',3);
pixel_labels = reshape(cluster_idx,nrows,ncols);
figure(2);
imshow(pixel_labels,[]),title('image labeled by cluster index');
segmented_images = cell(1,3);
rgb_label = repmat(pixel_labels,[1 1 3]);
for k = 1:nColors
color=he;
color(rgb_label ~= k) = 0;
segmented_images{k} = color;
end
figure(3);
imshow(segmented_images{1}),title('objects in cluster 1');
figure(4);
imshow(segmented_images{2}),title('objects in cluster 2');
figure(5);
imshow(segmented_images{3}),title('objects in cluster 3');
Output:
Result:

Thus the program was executed successfully and the output was verifed

You might also like