Digital Image Processing - Problem Set 1 Solutions | ECE 6258, Assignments of Digital Signal Processing

Material Type: Assignment; Class: Digital Image Processing; Subject: Electrical & Computer Engr; University: Georgia Institute of Technology-Main Campus; Term: Fall 2003;

Typology: Assignments

Pre 2010

Uploaded on 08/05/2009

koofers-user-om9
koofers-user-om9 🇺🇸

5

(1)

10 documents

1 / 11

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
GEORGIA INSTITUTE OF TECHNOLOGY
School of Electrical and Computer Engineering
ECE 6258
Digital Image Processing
Fall 2003
Problem Set #1 – Solutions
Problem 1.1:
The following solution is from Sarju Vaz.
(a)
clear all, close all
% open the image
[I, cmap] = imread('cameraman.tiff');
figure, subplot(221), imshow(I)
I = double(I);
min_I = min(I(:))
max_I = max(I(:))
orig_num_levels = max_I - min_I + 1
% Quantize the image to 10 uniformly spaced gray levels
quant_num_levels = 10
%size of quantization bin (cover for even bin size)
quant_bin_size = orig_num_levels/quant_num_levels
xlabel(sprintf(...
'pixel values range from %d to %d\nNum gray levels in orig image = %d\nNum
quantization levels = %d\nQuantization bin width ~ %.2f',...
min_I, max_I, orig_num_levels, quant_num_levels, quant_bin_size))
%Go with ceil(quant_bin_size) as long as
[quant_bin_size*ceil(quant_bin_size)] <= 256
subplot(222), imhist(uint8(I))
bin_size = ceil(quant_bin_size)
mid_val = floor(bin_size/2) % more intuitive --> ceil(..)-1, but this is because we start
from 0
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download Digital Image Processing - Problem Set 1 Solutions | ECE 6258 and more Assignments Digital Signal Processing in PDF only on Docsity!

GEORGIA INSTITUTE OF TECHNOLOGY

School of Electrical and Computer Engineering

ECE 6258 Digital Image Processing Fall 2003

Problem Set #1 – Solutions

Problem 1.1:

The following solution is from Sarju Vaz.

(a)

clear all, close all

% open the image [I, cmap] = imread('cameraman.tiff'); figure, subplot(221), imshow(I) I = double(I);

min_I = min(I(:)) max_I = max(I(:)) orig_num_levels = max_I - min_I + 1

% Quantize the image to 10 uniformly spaced gray levels quant_num_levels = 10

%size of quantization bin (cover for even bin size) quant_bin_size = orig_num_levels/quant_num_levels

xlabel(sprintf(... 'pixel values range from %d to %d\nNum gray levels in orig image = %d\nNum quantization levels = %d\nQuantization bin width ~ %.2f',... min_I, max_I, orig_num_levels, quant_num_levels, quant_bin_size))

%Go with ceil(quant_bin_size) as long as [quant_bin_size*ceil(quant_bin_size)] <= 256

subplot(222), imhist(uint8(I))

bin_size = ceil(quant_bin_size) mid_val = floor(bin_size/2) % more intuitive --> ceil(..)-1, but this is because we start from 0

% calculate shift ranges: non_supported_intervals = [min_I, 255 - ([(quant_num_levels-1) * bin_size] + mid_val)] % we definetely don't want any bin value to be < min_I or > max_I

% the inclusive range covered between the extreme bin vals min2max_tight = (quant_num_levels - 1)*bin_size + 1

root_bin_vect = 0: bin_size: (quant_num_levels - 1)*bin_size

first_bin_vect = min_I: max_I - min2max_tight + 1 % ** in practice would have to use some logic to % get the smaller of the numbers in front

% initialize

% for qq = 1:length(first_bin_vect) % bin_val = first_bin_vect(qq) % shift_val = mid_val - bin_val %[5 : -16] % % shifted_I = (I + shift_val); % could contain - values or values >= % % positive_sI = shifted_I > 0; % truncated_sI = shifted_I .* positive_sI; % essentially mask the down-shifted I % % raw_quant_I = floor( truncated_sI ./ bin_size); % if max(raw_quant_I(:)) >= quant_num_levels % out_of_bounds_I_adjust = raw_quant_I >= quant_num_levels; % we know that in this case max(raw_quant_I)== % % so we use the nifty short cut. % % Else have to do a find and replace % % raw_quant_I = raw_quant_I - out_of_bounds_I_adjust; % end % % quant_I = bin_size * raw_quant_I + bin_val; % % max(quant_I(:)) % % CAE = sum(abs(I(:) - quant_I(:))) % cumilative absolute error % %my_MSE = sum((I(:) - quant_I(:)).^2)/length(I(:)) % matlab_MSE = MSE(I(:) - quant_I(:)) % if qq == 1 % min_MSE = matlab_MSE; % first_bin = bin_val;

shifted_I = (dithered_I + shift_val); % could contain - values or values >=

positive_sI = shifted_I > 0; truncated_sI = shifted_I .* positive_sI; % essentially mask the shifted I

raw_quant_I = floor( truncated_sI ./ bin_size); if max(raw_quant_I(:)) >= quant_num_levels out_of_bounds_I_adjust = raw_quant_I >= quant_num_levels; % we know that in this case max(raw_quant_I)== % so we use the nifty short cut. % Else have to do a find and replace

raw_quant_I = raw_quant_I - out_of_bounds_I_adjust; end

quant_dI = bin_size * raw_quant_I + bin_val;

matlab_MSE2 = MSE(I(:) - quant_dI(:))

figure, subplot(131), imshow(uint8(I)), title('original image') subplot(132), imshow(uint8(quant_I)), title('quantized image from part (a)'), xlabel('MSE = 41.809') subplot(133), imshow(uint8(quant_dI)), title(sprintf('dithered and then quantized image\nusing the same bins as in part (a)')) xlabel(sprintf('MSE = %.3f',matlab_MSE2))

(b)

I_thresh = I_green > 40; figure, subplot(221), imshow(I) subplot(222), imshow(I_thresh)

% 2. BWLABEL and identify the largest foreground object (but fill holes first) hole_filled_I_thresh = bwfill(I_thresh, 'holes')

[L, num_connected_objs] = bwlabel(hole_filled_I_thresh,4); % L is the LABELED img % num_connected_objs is FOREGROUND objects (0-bin is background) [count, bins] = hist(L(:), 0:num_connected_objs); [max_val, pos] = max(count(2:end)) % pos ends up being the right val because the % first count value is for the zero bin

Largest_FG_Obj = L==pos subplot(223), imshow(Largest_FG_Obj)

% 3. At this point we have to define "Area of the island" % i. Total Area of island (including water bodies etc, such as lakes) area_1 = max_val * (30/(1e3))^ xlabel(sprintf... ('Approximate "total area" of the island is %.2f square kilometers', area_1))

% ii. Area of land part alone of the island (mask I_thresh with % Largest_FG_Obj)

masked_island = I_thresh & Largest_FG_Obj; subplot(224), imshow(masked_island) [count_2, bins_2] = hist(masked_island(:), [0 1]); area_2 = count_2(2) * (30/(1e3))^ xlabel(sprintf... ('Approximate "land area" of the island is %.2f square kilometers', area_2))

Problem 1.3:

The above figure shows the sequences involved in the convolution. x [ n 1 , n 2 ] is shown as solid dots; x[ n 1 - m 1 , n 2 - m 2 ] is shown as a shaded region. Both sequences are wedge- shaped and the apex of x[ n 1 - m 1 , n 2 - m 2 ] is at the point [ n 1 , n 2 ]. If n 2 n 1 ≥ 0, the region of overlap is a parallelogram; it is zero otherwise. The parallelogram has a horizontal extent of n 1 +1 samples and a vertical extent of n 2 - n 1 +1 samples. Therefore,

y[ n 1 , n 2 ] = ( n 1 +1)( n 2 - n 1 +1), if n 2 ≥ n 1 ≥ 0 0, otherwise.