0% found this document useful (0 votes)
14 views7 pages

Lab1 110061203

Uploaded by

yuqiwang677
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views7 pages

Lab1 110061203

Uploaded by

yuqiwang677
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

DSP 實驗 110061203 王譽錡 Wang,Yu-Chi

Lab1

(1).

YUV 圖像:

(2).
flipping:
原圖: vertical flipping:
horizontal flipping: both flipping:

(3).rotation

(4).shearing
(5). resize in a scale of 0.6 (per side)

(原圖及縮圖放在一起比較)

The flow:
(1). For the first step is to initialize and separate RGB channels and thus calculate the
rotation matrix and vertex positions after the rotation, by basing on the given rotation
angle, to fit in to compute the rotation matrix. I use the rotation matrix to make sure
the positions of the four corners of the image.
(2).Based on the vertices assigned at step 1, then we calculate the minimum and
maximal boundaries of the new image. We may know how much to shift the image
and to calculate the new width and height of the rotated image. Step1 and2 is the
same as backward warping.
(3).Then we perform forward warping, for each pixel in the original image, multiply
with degrees to its new position after rotation and assign its value to the new position
in the rotated image.
(4).I discover there are some black spots or distortion so I have to fill in the black
spots. To Fill in these gaps using neighboring filled pixels, either from up to down or
from the left to right. This way still contain a little distortion but other ways, such as
Bilinear Interpolation, to totally deal with it, but it is too laboring-tasking to me.
(5).At last, we combine the rotated RGB channels to create the final rotated image
(I_rotfw).
Result Image:

For the backward warping, each pixel in the target image, the function calculates
where it came from in the source image using the inverse of the transformation. The
source pixel values are then transformed to the new image’s position by dragging
them to the correct position.

And for forward warping, each pixel in the source image is transformed using a
mathematical function of rotation. The transformed coordinates assigned the pixel's
new position in the target image. The outside function then assigns the pixel’s value
from the source image to the position in the target image. But it will have some black
spots if no gaps is filled. The function I added at step 5 of the file
(rotation_forward.m) to checks if a pixel is empty (black) and simply mimic a nearby
pixel, from the row above or the column to the left. This ensures that empty spots are
filled with specific values. However if we expand the image, there will be some
distortion.

And their biggest differences is their iteration, for forward warping they iterates over
source pixels and places them in the target image while the backward one iterates
over those of source image. And from the respect of matrix transformation, the
forward warping directly applies the transformation to source pixels while the
backward one applies the transformation to target pixels.
(1)
For the substitution of image flipping, I discard the function of flipud and fliplr for
the use of double for loop, take horizontal flipping for instance.(the vertical one is
made in the same method)
For outer loop (from i = 1:height), it iterates over each row. We are flipping each row
independently. Inside loop (for j = 1:width), and this loop goes through each pixel in
the row to across the width of the image (j represents the column number).The pixel
at position (i, j) in the original image is replaced by the pixel at (i, width - j + 1) in the
flipped image. This moves pixels from the right to the left side of the row. And this
sentence (R_flip(i, j) = R(i, width - j + 1)), means that for each pixel at position (i, j)
in the flipped image, we assign the value from the corresponding pixel at position (i,
width - j + 1) in the original image.

And for both horizontal and vertical flipping, for each pixel at position (i, j), the
flipped image gets its value from the pixel at (height - i + 1, width - j + 1). This flips
both vertically and horizontally by the iteration.
(2)
For the substitution of rotation, the first 5 steps is almost the same as the backward
warping. First we set an input and initialize then we define a rotation matrix and
compute new image corners. Then we start to find boundaries of the Rotated Image.
The minimum and maximum coordinates of the rotated image are computed using
min and max function. This shows the boundaries for the new image. These values
can be used to calculate the new width and height of the rotated image.
Then we shift to positive axis because the rotated image might have negative
coordinates (because it is 360 degrees), the shift is applied to make sure all
coordinates are positive. The amount of shift is calculated based on the minimum x
and y coordinates. Then we initialize the new image’s three zero matrixes which are
created to store the pixel values for the new rotated image.
By using the nearest-neighbor method, for each pixel in the rotated image, the
corresponding pixel location in the original image is calculated using the inverse
rotation formula. Then we assign nearest pixel values, if the calculated coordinates
are within the bounds of the original image, the RGB values from the nearest pixel in
the original image are assigned to the corresponding location in the new rotated
image. If the pixel falls outside the bounds of the original image, the pixel is assigned
a value of empty(black).

(3)
For the substitution of resize, I utilize the imresize function. The function first
separates and label the RGB channels of the input image. Then, it uses inner
imresize function to scale each channel individually. Finally, it combines the
resized RGB channels back into a single image (I_res). (我將兩縮圖並排做比較)
5. conclusion

This HW remind me of some simple technique I have learned in my freshman year,


and it is a good review for some concept of coding. By the way, there are some
mistakes I’ve made instinctively making the color of the picture quite weird or some
blur rather than printing out intact picture. So some revise on the rounding of interger
of the pixels and doubling of the I is required. All in all, I still being quite familiar
with some methods of image transformation.

You might also like