1 2 3 4 5 6 7 8 9 10 | %% My MATLAB code for finding new equilized histogram r = [23 12 354 580 215 35 48 8] pr = r/sum(r) t= cumsum(pr)*(length(r)-1) T = round(t) NewHist = zeros(size(T)); for i=unique(T) NewHist(i+1) = sum(r(T==i)); end stem(NewHist) |
Digital Image Processing - AGU
Tuesday, 3 May 2016
My MATLAB code for histogram equalization
Check this code. I couldn't make it without a for loop. Let me know, if there is a smarter way for it.
Saturday, 30 April 2016
HW 5 - Morphological operations
Due: 6 May Friday, 23.59
Do not use MATLAB's morphological operations. The point of the HW is to implement morphological operations in your own way.
Q1 - Write a MATLAB function which takes an binary image a structuring element as arguments and returns eroded binary image as output.
Q2 - Write a MATLAB function which takes an binary image a structuring element as arguments and returns dilated binary image as output.
Q3 - Using your answers in Q1 and Q2, write a MATLAB function which takes an binary image a structuring element as arguments and returns opened binary image as output.
Q4 - Using your answers in Q1 and Q2, write a MATLAB function which takes an binary image a structuring element as arguments and returns closed binary image as output.
Q5 - Using your previous answers, write a MATLAB function for boundary extraction which takes an binary image and returns its boundaries.
Do not use MATLAB's morphological operations. The point of the HW is to implement morphological operations in your own way.
Q1 - Write a MATLAB function which takes an binary image a structuring element as arguments and returns eroded binary image as output.
1 2 3 4 | function B = erode(I, SE) %I: a binary 2D image %SE: a binary 2D SE %B: eroded element. |
Q2 - Write a MATLAB function which takes an binary image a structuring element as arguments and returns dilated binary image as output.
Q3 - Using your answers in Q1 and Q2, write a MATLAB function which takes an binary image a structuring element as arguments and returns opened binary image as output.
Q4 - Using your answers in Q1 and Q2, write a MATLAB function which takes an binary image a structuring element as arguments and returns closed binary image as output.
Q5 - Using your previous answers, write a MATLAB function for boundary extraction which takes an binary image and returns its boundaries.
Sunday, 17 April 2016
HW4 - WIENER FILTERING
Due date: 25 April 2016, Monday, 23:59 (It is a long HW. Better off starting now)
DIGITAL IMAGE PROCESSING
HOMEWORK 4
WIENER FILTERING
Give each of your answer in a separate section.
Note: To create a new section, just add two percentage character %% and a space, then your title.
Ex:
%% Adding Motion blur
a = ...
(50 points) Q1) Spatial domain
See http://uk.mathworks.com/help/images/examples/deblurring-images-using-a-wiener-filter.html
A) Write a MATLAB script section that reads the parrots image provided below.
Create another section for adding motion blur to the image.
Add a motion blur in 45 degree direction with 44 pixels length.
I got this image:
B) In a new section, restore the image using deconvolution wiener filter. See the link.
I got this:
C) In a new section, add a zero mean gaussian noise to the blurred image with variance 0.0001.
I got this:
D) In a new section, Try to restore the image using same method in B). You will fail. Explain why it fails.
I got this:
E) In a new section, restore the image utilizing the noise and signal variances. See the link.
I got this:
(100 points) Q2) Frequency domain
A) Implement motion blur effect in frequency domain. That is, implement the degradation function of it. See Eq. 5.6-10. Take T=1 and a=0.05. That applies motion blur in x direction only.
some part of my code is this:
%% Motion blur in Freq. domain
T=1; a= 0.05;
[u,v] = meshgrid(1:size(I,2),1:size(I,1));
H = ...
F = fft2(I);
G=F.*H; %note that this is dot multiplication. We never need matrix multiplication or division in this HW.
Ig = abs(ifft2(G));
imshow(Ig);
title('Motion blur in freq domain')
B) Apply inverse filtering.
...
FinvFiltered = G./H;
...
C) Add a zero mean UNIFORM noise in range [-0.001,0.001] in frequency domain to the blurry image.
D) Try inverse filtering on the noisy blurred image. It should fail. Explain the reason.
...
imagesc(InoisyInvFiltered)
...
E) Implement Wiener filter in frequency domain. See Eq. 5.8-2. Apply it assuming that we know power spectrum of noise and undegraded image. See end of page 375.
F) Suppose that we do not know power spectrum of noise or undegraded image. Then we give a constant value as in 5.8-6 and find the best K just by trial and error. Find the best K and apply Eq. 5.8-6.
Monday, 11 April 2016
Midterm 1 and Solutions
Questions:
Name:
Student ID:
05/04/2016
TUESDAY
ECE 599 DIGITAL IMAGE PROCESSING
- MIDTERM EXAM
Duration: 120min
Rules and notes: Closed book, no cheat-sheet. You can use your calculator. Please attempt all questions.
Grading
| ||||||
Q1
|
Q2
|
Q3
|
Q4
|
Q5
|
Q6
|
Total
|
10
|
15
|
20
|
15
|
20
|
20
|
100
|
Q1) Putting the corresponding numbers into the boxes below, order the following electromagnetic waves in descending order with respect to their frequencies:
- X-rays,
- GSM signals (cell phones),
- Infrared,
- Ultraviolet,
- Red,
- Black,
- Blue,
- Gamma rays,
- Microwave,
- FM radio
Q2) Affine matrix of rotation is given in Fig. 1. Rotate the image in Fig. 2. by 60° and find new coordinates of the pixels. (Note: new coordinates do not need to be an integer.)
sin(60)=0.87, cos(60)=0.5,
|
| ||||||||||||||||||||||
Q3) In an 2 bit image (That is, pixels can take values between 0 and 3), number of occurrences of each of pixel values (histogram) are given as:
n0 (Black) = 0,
n1 = 5,
n2 = 80,
n3 = 15
a) Find histogram equalization transformation function of this image. Show your work.
b) Apply the transformation function and find the equalized histogram. Plot it.
Q4) In Fig. 3, a 3x3 box filter in spatial domain (not in frequency domain) is given. We can use box filters to soften the image. If we want even softer image, we apply it again. Find a filter which gives the same effect with applying the box filter in Fig. 3 for two times. (Hint: size of your filter might be bigger than the original box filter.)
1/9
|
1/9
|
1/9
|
1/9
|
1/9
|
1/9
|
1/9
|
1/9
|
1/9
|
Figure 3. A box filter
| ||
Q5) Magnitude plot of frequency domain representation of function f(t) is given in Fig. 4. The following questions are related to Fig. 4.
Figure 4. Magnitude of F(𝞵), which is Fourier transform of f(t).
- What would you see in frequency domain (draw) if you sample the signal f(t) in
- 250,
- 200,
- 150 and
- 100 Hz.
- After sampling it, in which cases is it possible to perfectly recover the original signal?
- For each case where there is no aliasing, How do you recover the original signal after sampling it ? (what kind of filter would you apply to it in freq. domain? (Box?) What are its cutoff frequencies?)
- For each case where there is aliasing, before sampling the signal, What would you do to prevent aliasing ? (Give numerical values of your filter.)
Q6) Roughly sketch magnitude of DFT of the image in Fig. 5. It is an image of an equilateral triangle with a thick bottom edge. Explain your drawing. (Hint: DFT of a rotated image rotates in same degree.)
Figure 5. An image
Good Luck!
Monday, 4 April 2016
HW3 solutions and some notes
I haven't double checked the solutions but it looked correct to me. You can comment on the post if you have any comment or question.
CORRECTION:
- In some questions, output of a filtering operation might have negative values. Do not normalize the result in between [0,255] as it is incorrectly done below answers.
- Histogram equalization is not correct. I found this transfer function [0 0 2 5 7 7 7 7]; You can use my histogram equalization code for checking:
1 2 3 4 5 6 7 8 9 10 | %% My MATLAB code for finding new equilized histogram r = [23 12 354 580 215 35 48 8] pr = r/sum(r) t= cumsum(pr)*(length(r)-1) T = round(t) NewHist = zeros(size(T)); for i=unique(T) NewHist(i+1) = sum(r(T==i)); end stem(NewHist) |
------------
FFT of sobel
[u,v] = meshgrid(-1:0.1:1);
Fuv = -4j*sin(2*pi*u/3)-2j*sin(2*pi*(u/3+v/3))-2j*sin(2*pi*(u/3-v/3));
mesh(Fuv*1j)
FFT of Q7
I = zeros(100);
I(:,20:30) = 1;
F = fftshift(fft2(I));
imshow(abs(F),[0,100]);
Saturday, 2 April 2016
Midterm Tips and Some Notes on That
Midterm exam will be on the regular lecture time (9:00 Tuesday, April 5)
Closed book, no cheat-sheet. Bring your calculator!
Tips before the midterm exam:
- Check this blog regularly before the midterm. I might add some more tips.
- Make sure that you can answer all of the previous homework questions and the following questions:
- Ruminate on Fig. 4.24 and 4.25. Try to guess magnitude of FFT of other geometrical shapes and that of their rotated versions.
- Find out what you would see in frequency domain (draw) if you sample the following signal in
- 250,
- 200,
- 150 and
- 100 Hz.
- After sampling it, in which cases is it possible to perfectly recover the original signal?
- For each case where there is no aliasing, How do you recover the original signal after sampling it ? (what kind of filter would you apply to it in freq. domain? (Box?) What are its cutoff frequencies?)
- For each case where there is aliasing, before sampling the signal, What would you do to prevent aliasing ? (Give numerical values of your filter.)
Subscribe to:
Comments (Atom)






















