Professional Documents
Culture Documents
Dip Programs
Dip Programs
Dip Programs
clc;
close all;
originalImage = imread('onion.png');
grayImage = rgb2gray(originalImage);
sobelHorizontal = [-1,0,1;-2,0,2;-1,0,1];
sobelvertical =[-1,-2,-1;0,0,0;1,2,1];
[rows,cols] = size(grayImage);
gradientMagnitude = zeros(rows,cols);
for i = 2:rows-1 for j = 2:cols-1
gx = sum(sum(double(grayImage(i-1:i+1, j-1:j+1)) .* sobelHorizontal));
gy = sum(sum(double(grayImage(i-1:i+1, j-1:j+1)) .* sobelvertical));
laplaciankernel = [0,-1,0;-1,4,-1;0,-1,0];
[rows,cols,~] = size(originalImage);
sharpenedImage = zeros(rows,cols,3);
output:
5)Program for Display of an Image, negative of an
Image(Binary&Gray scale):
clc;
close all;
input_image=imread('C:\Users\SYSTEM25\Desktop\computer.jpg');
subplot(1,2,1);
imshow(input_image);
title('Original Image');
negative_image=255-input_image;
subplot(1,2,2);
imshow(negative_image);
title('negative of Original Image');
Output:
7)Program for implementation of transformation of an
image:
clc;
close all;
original_image=imread('C:\Users\SYSTEM25\Desktop\rose2.jpg');
input_image=rgb2gray(original_image);
subplot(2,3,2);
imshow(input_image);
title('Original Image');
%Logarithmic Transform
L=255;
c=L/log10(1+L);
log_transform=c*log10(1+double(input_image));
subplot(2,3,5);
imshow(uint8(log_transform));
title('Log Transformation');
Output:
8)program for contrast stretching of a low contrast
image,Histogram,andHistogram Equualization:
clc;
close all;
inputImage=imread('C:\Users\SYSTEM25\Desktop\e.jpg');
if size(inputImage,3)==3
inputImage = rgb2gray(inputImage);end
grayImage=im2double(inputImage);
%Apply contrast stretching to enhance the image contrast
minIntensity=min(grayImage(:));
maxIntensity=max(grayImage(:));
contrastStretchedImage=(grayImage-minIntensity)/(maxIntensity-minIntensity);
%Computer the histogram of the original and contrast-stretched images
originalHistogram=computeHistogram(grayImage);
contrastStretchedHistogram=computeHistogram(contrastStretchedImage);
%perfrom histogram equalization to enhance the image contrast
histEqualizedImage=histogramEqualization(grayImage);
%compute the histogram of the equalized image
equalizedHistogram = computeHistogram(histEqualizedImage);
subplot(3,2,1);imshow(grayImage);title('Original Image');
subplot(3,2,2);bar(originalHistogram);title('Original Image');
subplot(3,2,3);imshow(contrastStretchedImage);title('contrast Stretched
Image');
subplot(3,2,4);bar(contrastStretchedHistogram);title('Histogram(contrast
Stretched Image)');
subplot(3,2,5);imshow(histEqualizedImage);title('Histogram Equalized
Image');
subplot(3,2,6);bar(equalizedHistogram);title('Histogram Equalized Image');
OUTPUT:
16)program for Implementation of Image Intensity slicing
technique for image enhancement:
clc;
close all;
input_image=imread('C:\Users\SYSTEM25\Desktop\doremon.jpg');
if size(input_image,3)==3
input_image=rgb2gray(input_image);
end
lower_threshold=120;
upper_threshold=200;
new_intensity=255;
enhanced_image=intensitySlicing(input_image,lower_threshold,upper_threshold,n
ew_intensity);
subplot(1,2,1);imshow(input_image);title('Original Image');
subplot(1,2,2);imshow(enhanced_image);title('Enhanced Image');
function
enhanced_image=intensitySlicing(input_image,lower_threshold,upper_threshold,n
ew_intensity)
[height,width]=size(input_image);
enhanced_image=zeros(height,width);
for y=1:height
for x=1:width
intensity=input_image(y,x);
if intensity >=lower_threshold && intensity <=upper_threshold
enhanced_image(y,x)=new_intensity;
else
enhanced_image(y,x)=intensity;
end
end
end
enhanced_image=cast(enhanced_image,class(input_image));
end
Output:
17)program for canny edge detection Algorithm:
clc;
close all;
inputImage = imread('onion.png');
if size(inputImage,3)==3
inputImage = rgb2gray(inputImage);
end
cannyEdges = edge(inputImage,'canny');
subplot(1,2,1);imshow(inputImage);title('Original Image');
subplot(1,2,2);imshow(cannyEdges);title('canny Edges');
Output:
18)program to obtain histogram equalization concept:
clc;
close all;
input_image = imread('cameraman.tif');
if size(input_image,3)==3
input_image = rgb2gray(input_image);
end
subplot(2,2,1);imshow(input_image);title('Original Image');
subplot(2,2,3);imhist(input_image);axis tight;title('Bfr Histogram
Equilization');
[rows,cols] = size(input_image);
total_no_pixel=rows*cols;
% calculate the histogram of two input image
histogram = zeros(1,256);
for i = 1:rows
for j = 1:cols
histogram(input_image(i,j)+1) = histogram(input_image(i,j)+1)+1;
end
end
%calcuating probalilty
for i = 1 : 256
histogram(i) = histogram(i) / total_no_pixel;
end
temp = histogram(1);
for i = 2:256
temp = temp+histogram(i);
histogram (i) = temp;
end
%mapping
for i = 1:rows
for j = 1:cols
input_image(i,j) = round(histogram(input_image(i,j)+1) *255);
end
end
subplot(2,2,2);imshow(input_image);title('Equalized Image');
subplot(2,2,4);imhist(input_image);axis tight;title('Afr Histogram Equalized
Image');
Output:
19)program to Implement smoothing or averaging filter in
spatial domain:
clc;
close all;
originalImage=imread('C:\Users\SYSTEM25\Desktop\doremon.jpg');
if size(originalImage,3)==3
originalImage=rgb2gray(originalImage);
end
grayImage=im2double(originalImage);
filterSize=5;
paddingSize=floor(filterSize/2);
[rows,cols]=size(grayImage);
smoothedImage=zeros(rows,cols);
for row=1:rows
for col=1:cols
neighborhood=grayImage(max(row-
paddingSize,1):min(row+paddingSize,rows),max(col-
paddingSize,1):min(col+paddingSize,cols));
smoothedValue=mean(neighborhood(:));
smoothedImage(row,col)=smoothedValue;
end
end
subplot(1,2,1);imshow(grayImage);
title('Original Image');
subplot(1,2,2);imshow(smoothedImage);
title('Smoothed Image');
Output:
22)Program to compute the edges in the image using
Roberts,sobel,Canny,Log,prewitt edge detection methods:
clc;
close all;
inputImage=imread('C:\Users\SYSTEM25\Desktop\computer.jpg');
if size(inputImage,3)==3
inputImage=rgb2gray(inputImage);
end
cannyEdges=edge(inputImage,'Canny');
sobelEdges=edge(inputImage,'sobel');
robertEdges=edge(inputImage,'roberts');
perwittEdges=edge(inputImage,'prewitt');
logEdges=edge(inputImage,'Log');
subplot(3,3,1);imshow(inputImage);title('Original Image');
subplot(3,3,2);imshow(robertEdges);title('Roberts Edges');
subplot(3,3,3);imshow(sobelEdges);title('Sobel Edges');
subplot(3,3,4);imshow(cannyEdges);title('Canny Edges');
subplot(3,3,5);imshow(perwittEdges);title('Perwitt Edges');
subplot(3,3,6);imshow(logEdges);title('Log Edges');
Output:
25) Program to separate the RGB plane from the color
Image:-->
clc;
clear all;
close all;
input_image=imread('C:\Users\SYSTEM25\Desktop\doremon.jpg');
red_color=input_image;
green_color=input_image;
blue_color=input_image;
red_color(:,:,2)=0;
red_color(:,:,3)=0;
green_color(:,:,1)=0;
green_color(:,:,3)=0;
blue_color(:,:,1)=0;
blue_color(:,:,2)=0;
subplot(2,3,2);
imshow(input_image);
title('Original RGB Image');
subplot(2,3,4);
imshow(red_color);
title('Red Color Plane');
subplot(2,3,5);
imshow(green_color);
title('Green Color Plane');
subplot(2,3,6);
imshow(blue_color);
title('Blue Color Plane');
Output: