This project shows ideas that are in my opinion a must for anyone who wish to understand digital image processing.
Requirements:
- Calculus
- Linear algebra
- probability
- Matlab or Octave with image processing packages
In these assignment we wrote a function that receives a gray-scale image and returns a gray-scale image obtained by applying the histogram shape algorithm on this image where the histogram of the result image should match the histogram of the destimg.
In order to implement the histShape algorithm we must first know more about:
function [ newImg ] = histShape( srcimg, destimg )
%histShape This function creates new image from srcimg with destimg histogram.
%
% INPUT PARAMETERS
% srcimg - uint8 matrix
% destimg - uint8 matrix
%
% OUTPUT PARAMETERS
% newImg - uint8 matrix (same size as srcimg)
%
OFFSET = 1;
[N, M] = size(srcimg);
cv = computeConversionVector(srcimg, destimg);
newImg = zeros(size(srcimg), 'uint8');
for i = 1:N
for j = 1:M
newImg(i, j) = cv(srcimg(i, j) + OFFSET);
end
end
end
For the rest of the code click here.
% Let srcimg be the Source image
% Let destimg be the image we wish to match it's histogram.
srcimg = imread('darkimg.tiff');
destimg - imread('flatHist.tiff');
output = histShape(srcimg, destimg);
imshow(srcimg); figure; imshow(destimg); figure; imshow(output);
This assignment was about image enhancement from different types of noise from an image. More about the topic can be found here
In this part of the assignment we wrote a function which receive an image and add gaussian noise to the image with mean value 0, and var=0.004, and then we've try to enhance the image using the directional smoothing. It is up to us, to choose the right directional filters (size, orientation, and values).
Function signature :
function [eImg,nImg] = gaussEnhance(img)
One should pay attention for overfitting the filters to the noised image.
function [newImg] = computeSmoothenImage(img, c1, c2, c3, c4, c5, c6, c7)
% Computes the smoothen image form the img and the image after filters
% by choosing the closest value from filtered image to the original image at
% position i, j.
[N, M] = size(img);
newImg = zeros(size(img));
for i = 1:N
for j = 1:M
val = img(i, j);
filtered = [c1(i, j), c2(i, j), c3(i, j), c4(i, j), c5(i, j), c6(i, j), c7(i, j)];
[_, I] = min(abs(val - filtered));
newImg(i, j) = filtered(I);
end
end
end
img = imread('house.tiff');
[eImg,nImg] = gaussEnhance(img)
In this part we've wrote a function which receive an image and add shaped noise given by the following matrix:
[1,0,0,0,1;1,0,0,0,1;0,1,0,1,0;0,1,0,1,0;0,0,1,0,0]
The function should then try to enhance the image using myMedian filter.
Function signature :
function [eImg,nImg] = shapesEnhance(img)
Due to the shape of the noise we can apply a median filter of the shape (1, 5)
to enhance the image.
function [eImg,nImg] = shapesEnhance(img)
% This function adds shaped noise which is given by the following matrix:
% [1,0,0,0,1;
% 1,0,0,0,1;
% 0,1,0,1,0;
% 0,1,0,1,0;
% 0,0,1,0,0].
%
% with density of 0.003.
% then removes the noise with 5 x 1 median filter.
%
%
% INPUT PARAMETERS
% img - matrix of doubles
%
%
% OUTPUT PARAMETERS
% eImg - enhansed image, matrix of doubles
% nImg - noisy image, matrix of doubles
mask = zeros(size(img));
mask = imnoise(mask, 'salt & pepper', 0.003);
noiseMat = [1,0,0,0,1;
1,0,0,0,1;
0,1,0,1,0;
0,1,0,1,0;
0,0,1,0,0];
mask = conv2(mask, noiseMat, 'same');
mask = min(mask, 1);
nImg = max(mask, img);
eImg = myMedian(nImg, 5, 1);
end
img = imread('house.tiff');
[eImg,nImg] = shapesEnhance(img)
This assignment was about binary images. More about the topic can be found here.
In this part we've wrote a matlab function which finds the connected components in a binary image and returns a matrix with the same size in which each connected component is tagged with a different label. The tags should be sequential.
More about connected components can be found here.
Function signature :
function [newImg] = tagConnectedComponents(img)
This algorithm considers 4-connectivity.
Let I be the input image size N x M.
-
Calculate equivalence table EQ:
-
Create conversion vector:
-
Convert the tags of T by the conversion vector.
function [newImg] = tagConnectedComponents(img)
% This function finds the connected components in a binary image and returns a
%matrix with the same size in which each connected components is tagged with a
%different label in a sequential manner.
%
% INPUT PARAMETERS
% img - binary image
%
% OUTPUT PARAMETERS
% newImg - matrix of doubles
%
pImg = padarray (img, [1, 1], 'pre');
[tagMatrix] = initTagMatrix(pImg);
eqTable = makeEqTalbe(tagMatrix);
cv = makeConvertionVector(eqTable);
newImg = tagImage(tagMatrix, cv);
newImg = newImg(2:end, 2:end);
end
img = imread('binary1.tiff');
output = tagConnectedComponents(img);
0 0 0 0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 0 0 0 9 0 0 0 0 9 0 0 0 0 0 0 0 0 9 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 9 0 0 0 0 9 0 0 5 5 5 5 0 0 9 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 9 0 0 0 0 9 0 0 5 0 0 5 0 0 9 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 9 0 0 0 0 9 0 0 5 0 0 5 0 0 9 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 9 0 0 0 0 9 0 0 0 0 0 5 0 0 9 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 9 0 0 0 0 9 0 0 0 0 0 5 0 0 9 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 9 0 0 0 0 9 9 9 9 9 9 9 0 0 9 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 9 0 0 0 0 0 0 0 0 0 0 0 0 0 9 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 9 0 0 0 0 0 0 0 0 0 0 0 0 0 9 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
In this part we've wrote a matlab function which skeletonize objects in a given binary image and returns a new binary image.
Function signature :
function [newImg] = skeletonizeImage(img)
- Calculate distance from background for each pixel.
- Mark every index where the pixel value is greater or equal to it's 4-connectivity neighborhood.
bwImg = imread('binaryRect.tiff');
output = skeletonizeImage(bwImg);
In this part of the Assignment we've implemented the Canny edge detector algorithm, more about it can be found here.
Function signature :
function [newImg, tgTeta] = edgeDetect(img)
The algorithm can be found here
img = im2double(imread('balls4.tiff'));
output = edgeDetect(img);
In this part of the Assignment we've implemented the Hough transform algorithm to find circles in an image, more about it can be found here.
Function signature :
function [circles,cImg] = findCircles(img)
The algorithm can be found here
img = im2double(imread('balls4.tiff'));
output = edgeDetect(img);
In this assignment we've cleaned images in the frequency domain.
Function signature :
function [cImg1,cImg2,cImg3,cImg4] = fftClean(img1,img2,img3,img4)
fft1 = im2double(imread('fft1.tiff'));
fft2 = im2double(imread('fft2.tiff'));
fft3 = im2double(imread('fft3.tiff'));
fft4 = im2double(imread('fft4.tiff'));
[cImg1,cImg2,cImg3,cImg4] = fftClean(fft1, fft2, fft3, fft4);
Write a matlab function which receives 2 gray-scale image and creates a new image, which is consists of tiles of the small image which forms the big image. Each of the small image tiles is processed using the histShape function of Ex1 to match the histogram of the big image in the same location.
Function signature :
function nImg = createTiledImage(bigImage, smallImage)
- Cut the big image to non overlapping parts of the size of the small image.
- Match the histogram of the small image to each of parts.
- Replace the parts with the matched small image.