Beruflich Dokumente
Kultur Dokumente
EE 440
HOMEWORK 1
REPORT
Class: 15ECE-CE
Le Quang Dao
Exercise 1 & 2
Fundamentals and Spatial Transformation
1. Read image with Matlab
a. Load the image lena512.bmp, using imread(), and show it using
imshow().
I = imread('lena512.bmp')
imshow(I)
b. Get the type of the loaded image data (Use MATLAB function class()),
and get the maximum and minimum data value for this image
I = imread('lena512.bmp')
a = max(max(I))
b = min(min(I,[],1))
ClassName = class(I)
Result:
a = 245
b = 25
ClassName = uint8
c. Convert the data to double type (use MATLAB function double()),
show the double-typed image using imshow()
I = imread('lena512.bmp')
double_I = double(I)
imshow(double_I)
The result is blank:
d. Is the result from c correct? If not, how do you think you can correct
it?
The result from c is not correct.
I = imread('lena512.bmp')
double_I = double(I)
imshow(uint8(double_I))
Before After
I = imread('kodim19.png');
[h,w,d] = size(I);
hi = h/4;wi = w/4;
new_I = zeros (h,w,d,'uint8');
for i = 1:4
for k = 1:4
x = ((i-1)*hi+1):i*hi;
y = ((k-1)*wi+1):k*wi;
a = ((4-i)*hi+1):(5-i)*hi;
b = ((4-k)*wi+1):(5-k)*wi;
new_I(x,y,1:d) = I(a ,b ,1:d);
end
end
figure;
subplot(1,2,1);imshow(I);
subplot(1,2,2);imshow(new_I);
Before After
3. Write an image
a. Reload the image LightHouse_color.png from exercise 2
RGB = imread('kodim19.png');
b. Exchange the plans R and G of this image, show the resulting image
[h,w,d] = size(RGB);
GRB = zeros(h,w,d,'uint8');
GRB(1:h,1:w,1) = RGB(1:h,1:w,2);
GRB(1:h,1:w,2) = RGB(1:h,1:w,1);
GRB(1:h,1:w,3) = RGB(1:h,1:w,3);
subplot(1,2,1);imshow(RGB);
subplot(1,2,2);imshow(GRB);
Before After
c. Using imwrite to generate an image file for this new color image (for
example bmp file). Check on your computer whether it is correct.
imwrite(GRB,'GRBlighthouse.bmp');
4. Read a video with Matlab
a. Choose a video (for example an .avi file) from your computer or Internet
b. Using VideoReader to load this video
video = VideoReader('abc.mp4')
5. Image rotation
a. Load a grayscale image
I = imread('lena512.bmp');
b. Use imrotate to rotate this image with 45°, and then with 90°
I45 = imrotate(I,45);
I90 = imrotate(I,90);
c. Show the original image and the rotated image in the same figure (using
subplot)
I = imread('lena512.bmp');
I45 = imrotate(I,45);
I90 = imrotate(I,90);
subplot(1,3,1);imshow(I);
subplot(1,3,2);imshow(I45);
subplot(1,3,3);imshow(I90);
e. Write a program to carry out the rotation of an image, i.e. do not use
the function imrotate. Compare with the results from question b.
The function carrying out the rotating:
function ImRotated = RotateFunction(im, degree);
% General rotations
otherwise
% Assign
ImRotated(i,j,:) =
sum(sum(cols),2);
end
end
end
end
subplot(1,2,1);imshow(I);
subplot(1,2,2);imshow(Y);
Before After
7. Quantization
a. Load an grayscale image.
I = imread('lena512.bmp');
b. Quantize this image if 6 bits are used to represent an intensity value.
Show the result
c. Repeat question b with 4 bits and 1 bit. Show the original image and all
the obtained results (from questions b and c) in the same figure.
I = imread('lena512.bmp');
Idouble = double(I)/255;
I6bits = uint8(round(Idouble*63)*floor(255/63));
I4bits = uint8(round(Idouble*15)*floor(255/15));
I1bit = uint8(round(Idouble*1)*floor(255/1));
subplot(2,2,1);imshow(I); title('Original');
subplot(2,2,2);imshow(I4bits); title('6-bit image');
subplot(2,2,3);imshow(I6bits); title('4-bit image');
subplot(2,2,4);imshow(I1bit); title('1-bit image');
8. Statistics
a. Load the grayscale image Lena
I = imread('lena512.bmp');
b. Find the maximum and minimum intensity values of the image
max = max(I(:))
min = min(I(:))
c. Find the mean, standard deviation and variance of the intensity values
Mean = mean(I(:))
STD = std(double(I(:)))
Var = var(double(I(:)))
d. Divide the image into non-overlapping blocks of 8 x 8 pixels. The mean
of the intensity values of each block is then used to represent this block, i.e.
each block becomes one pixel. Show this resulting image (with smaller size)
and the original one in the same figure
I = imread('lena512.bmp');
for i = 0:63
for k = 0:63
block{i+1,k+1} = I(i*8+1 : (i+1)*8, k*8+1 :
(k+1)*8);
Y{i+1,k+1} = mean(block{i+1,k+1}(:));
end
end
Y = uint8(cell2mat(Y));
subplot(1,2,1);imshow(I);
subplot(1,2,2);imshow(Y);axis([-123 123 -123 123]);