Digital Image Processing Lab Experiment-1 Aim: Gray-Level Mapping Apparatus Used
Digital Image Processing Lab Experiment-1 Aim: Gray-Level Mapping Apparatus Used
Lab Experiment-1
Apparatus Used:
Theory:
Procedure
3. Right click, select vision motion and choose IMAQ create and choose image
type(specify U32) as grayscale.
4. Create control by choosing read image (IMAQ Read) and specifying the file path
(from which the image is to be acquired).
5. Similarly, create control for writing by choosing write image (IMAQ Write).
6. Create an indicator image for display to the front panel and join.
Block Diagram:
Output:
Result :
Thus ,the program to display level mapping using read and write operation was created.
Lab Experiment-2
Apparatus Used:
Matlab
Theory:
s = (L – 1) – r
since the input image of Einstein is an 8 bpp image, so the number of levels in this
image are 256. Putting 256 in the equation, we get this
s = 255 – r
So each value is subtracted by 255 and the result image has been shown above. So what
happens is that, the lighter pixels become dark and the darker picture becomes light.
And it results in image negative.
Program:
%Matlab Code:
img = imread('breast.jpg');
img2 = 1 - im2double(img);
figure;
Block Diagram:
Output:
Result:
Aim: To obtain gamma transformation of image with value 𝛾 : 0.50, 0.10, 2.0, 4.0
Apparatus Used:
Matlab
Theory:
Correcting gamma.
s=cr^γ
s=cr^(1/2.5)
Program:
%Matlab Code
img = imread('spine.jpg');
Result:
Aim:
Apparatus used:
Matlab
Theory:
Program:
%Matlab Code
clear all; close all;
img = imread('fourierspectrum.jpg');
img2 = log10(1+256*im2double(img));
img2 = [img2 - min(img2(:))] ./ max(img2(:) - min(img2(:)));
figure; subplot(1,2,1); imshow(img); title('Original Image');
subplot(1,2,2); imshow(img2); title('Image after Logarithmic
Output:
Result:
Aim:
Apparatus used:
Matlab
Theory:
The exponential and `raise to power' operators are two anamorphosis operators which
can be applied to grayscale images. Like the logarithmic transform, they are used to
change the dynamic range of an image. However, in contrast to the logarithmic
operator, they enhance high intensity pixel values.
where P and Q are the input and output images, respectively, b is the basis and c is the
scaling factor. As we can see from the formula, P=0 yields Q=c. To avoid the resulting
offset, many implementations subtract 1 from the exponential term before the scaling. Hence,
we get the following formula:
Program:
I=imread('trees.tif');
subplot(2,2,1);
imshow(J);
title('original image');
f=ones(3,3)/9;
h=imfilter(I,f,'circular');
subplot(2,2,2); imshow(h);
title(exponential image');
Output:
Result:
Aim:
Apparatus used:
Matlab
Theory:
Intensity level slicing means highlighting a specific range of intensities in an image. In other
words, we segment certain gray level regions from the rest of the image.
Suppose in an image, your region of interest always take value between say 80 to 150. So,
intensity level slicing highlights this range and now instead of looking at the whole image,
one can now focus on the highlighted region of interest.
Since, one can think of it as piecewise linear transformation function so this can be
implemented in several ways. Here, we will discuss the two basic type of slicing that is more
often used.
In the first type, we display the desired range of intensities in white and suppress all
other intensities to black or vice versa. This results in a binary image. The
transformation function for both the cases is shown below.
import cv2
import numpy as np
img = cv2.imread('D:/downloads/forest.jpg',0)
min_range = 10
max_range = 60
# Loop over the input image and if pixel value lies in desired range set it to 255 otherwise
set it to 0.
for i in range(row):
for j in range(column):
img1[i,j] = 255
else:
img1[i,j] = 0
cv2.waitKey(0)
Output:
Result:
Aim:
Apparatus used:
Matlab
Theory:
Pixels are digital numbers, each one composed of bits. Instead of highlighting
gray-level range, we could highlight the contribution made by each bit.
This method is useful and used in image compression.
Program:
%Matlab Code
clear all; close all;
img = imread('fractal.jpg');
figure;
subplot(2,2,1); imshow(img7); title('Bit-plane 7');
subplot(2,2,2); imshow(img6); title('Bit-plane 6');
subplot(2,2,3); imshow(img5); title('Bit-plane 5');
subplot(2,2,4); imshow(img4); title('Bit-plane 4');
figure;
Output:
Result:
Q. Histogram Processing
Write code for calculating the histogram of the image (input image 19). Display
the output as the “Histogram Graph”
Answer:
%Matlab Code
clear all; close all;
img1 = imread('pollen_dark.jpg'); img2 = imread('pollen_bright.jpg');
img3 = imread('pollen.jpg'); img4 = imread('pollen_highcontrast.jpg');
[hist1, bins1] = hist(double(img1(:)),256);
[hist2, bins2] = hist(double(img2(:)),256);
[hist3, bins3] = hist(double(img3(:)),256);
[hist4, bins4] = hist(double(img4(:)),256);
hist1 = hist1./length(img1(:)); hist2 = hist2./length(img2(:));
hist3 = hist3./length(img3(:)); hist4 = hist4./length(img4(:));
figure;
subplot(2,2,1); imshow(img1); title('Dark Image');
subplot(2,2,2); bar(bins1,hist1); title('Dark Image cdf');
axis([0 255 0 .1]); xlabel('Gray Level, r');
subplot(2,2,3); imshow(img2); title('Bright Image');
subplot(2,2,4); bar(bins2,hist2); title('Bright Image cdf');
axis([0 255 0 .1]); xlabel('Gray Level, r');
figure;
subplot(2,2,1); imshow(img3); title('Low-contrast Image');
subplot(2,2,2); bar(bins3,hist3); title('Low-contrast Image cdf');
axis([0 255 0 .1]); xlabel('Gray Level, r');
subplot(2,2,3); imshow(img4); title('High-contrast Image');
subplot(2,2,4); bar(bins4,hist4); title('High-contrast Image cdf');
axis([0 255 0 .1]); xlabel('Gray Level, r');
Output:
Lab Experiment-8
Aim:
Apparatus used:
Matlab
Theory:
Contrast-stretching transformations increase the contrast between the darks and the
lights. That transformation kept everything at relatively similar intensities and merely
stretched the histogram to fill the image's intensity domain. Sometimes you want to
stretch the intensity around a certain level. You end up with everything darker darks
being a lot darker and everything lighter being a lot lighter, with only a few levels of
gray around the level of interest.
Program:
I=imread('tire.tif');
I2=im2double(I);
m=mean2(I2)
contrast1=1./(1+(m./(I2+eps)).^4);
contrast2=1./(1+(m./(I2+eps)).^5);
contrast3=1./(1+(m./(I2+eps)).^10);
imshow(I2)
figure,imshow(contrast1)
figure,imshow(contrast2)
figure,imshow(contrast3)
Output:
Result: