Image Processing by point processing
This program will demonstrate various image enhancement techniques using gray level manipulationContents
Start
clear all; close all; clc;
Read the Image
x1 = imread('coins.png');
x = double(x1)/255;
imshow(x);
Digital Negative
In this method: f(x,y) = L-Im(x,y), where L is the largest gray level in the imagex_neg = 1-x; figure; imshow(x_neg)
Log Transformation
In this method: f(x,y) = c*log(Im(x,y)) where c is any constant and Im > 0for c = 0.4
c = 0.4; x_log = c*log(1+x); figure; imshow(abs(x_log));
For c = 3
c = 3; x_log = c*log(1+x); figure; imshow(abs(x_log));
Power Law Transformation
In this method: f(x,y) = c*Im(x,y)^g where c and g are positive constantsfor c = 0.5, g = 2
c = 0.5; g = 2; x_pow = c*x.^g; figure; imshow(abs(x_pow));for 1.5 = 2, g = 0.5
c = 1.5; g = 0.5; x_pow = c*x.^g; figure; imshow(abs(x_pow));
Contrast Stretching
This program demonstrate piecewise continuous gray level transformation here we user three regions as: 0 to a1 transformed with the slope of m1 and a2 to 255 with slope of m1m1 = 2.5; m3 = 0.8; a1 = 50; a2 = 120; c1 = 255 - 255*m3; m2 = (m3*a2+c1-m1*a1)/(a2-a1); c2 = m1*a1-m2*a1; [row col] = size(x1); x_contrast = ones(row,col); for i = 1:row for j = 1:col if x1(i,j) < a1 x_contrast(i,j) = x1(i,j)*m1; elseif x1(i,j) > a2 x_contrast(i,j) = x1(i,j)*m3+c1; else x_contrast(i,j) = x1(i,j)*m2; end end end figure;imshow(uint8(x_contrast)); y = [(0:a1-1)*m1 ((a1:a2-1))*m2+c2 (a2:255)*m3+c1]; figure; plot(y);
Gray Level Slicing
This program demonstrate the gray level slicing operation on imageWithout Background:
x_GLS = ones(row,col); a = 48; b = 80; c = 190; for i = 1:row for j = 1:col if x1(i,j) < a || x1(i,j) > b x_GLS(i,j) = c; else x_GLS(i,j) = 0; end end end figure;imshow(uint8(x_GLS)); y = [(0:a1-1)*0 (ones(1,a2-a1+1))*c (a2:255)*0]; figure; plot(y);
With Background:
c = 190; for i = 1:row for j = 1:col if x1(i,j) < a || x1(i,j) >b x_GLS(i,j) = c; else x_GLS(i,j) = x1(i,j); end end end figure;imshow(uint8(x_GLS)); y = [(0:a1-1) (ones(1,a2-a1+1))*c (a2:255)]; figure; plot(y);