· web viewπ/2 the x value is from length to 0. and similar to the x axis, at y axis i also can...

16
DIP HW2 b95905028 郭郭郭 PROBLEM 1 : SPATIAL WARPING A. Method and motivation: I separate the original image into three parts. For each part is at different part in the output image. The separation way is as bellow: First of all, I change the image coordinate to Cartesian coordinate with the formula { x=u y=width v ((v,u) is the original image and the (x,y) is Cartesian coordinate the width is the height of the original image) (in here, I don’t move the pixel to the middle of pixel y x

Upload: others

Post on 13-Feb-2020

0 views

Category:

Documents


0 download

TRANSCRIPT

Page 1:  · Web viewπ/2 the x value is from length to 0. And similar to the X axis, at Y axis I also can find the relevance to R. So if we want paint a point of coordinate in output image

        DIP HW2     b95905028 郭明鑫

PROBLEM 1 : SPATIAL WARPING

A.Method and motivation:I separate the original image into three parts. For each part is at different

part in the output image. The separation way is as bellow:

First of all, I change the image coordinate to Cartesian coordinate with the formula

{ x=uy=width−v

((v,u) is the original image and the (x,y) is Cartesian coordinate the

width is the height of the original image)

(in here, I don’t move the pixel to the middle of pixel box, so I have to deal with the problem of counting the ratio from original image to output image, however, without “-1/2” it becomes more easy to calculate the related point)

y

x

Page 2:  · Web viewπ/2 the x value is from length to 0. And similar to the X axis, at Y axis I also can find the relevance to R. So if we want paint a point of coordinate in output image

After converting the coordinate to the Cartesian, I change the coordinate to polar one with the formula:

{r=√x2+ y2∧¿θ=tan−1 yx

So we could present the original image and the output image with the polar image as follow:

In this two image, I can find the relation between the original image and the output image. Then we mirror the polar coordinate to Cartesian coordinate. Take the image above for example, the X axis is seems to relate to θ. When the θ grows from 0 to π/2 the x value is from length to 0. And similar to the X axis, at Y axis I also can find the relevance to R. So if we want paint a point of coordinate in output image of (R’, θ’), by the reverse translation, I should get the pixel value of (x,y) = ( length - length*θ’/(π/2) , width*R’/(R/2) )(in the image coordinate) (length - length*θ’/(π/2) , width – width*R’/(R/2))

By the method above, I could done the apple without the leaf.Processing the leaf is more difficult. First I have to mark the region of the leaf. The leaf is the overlap of two quarter. So I need to use the character of the circle.And use the diagonal is exactly x=y(x-y=0),We can find the edge of the circle by the method:

1. Find the cross point is I (p,q) = (x/2, y/2) 2. Count the vector n = (x-p, y-q)

3. Present the green point by the parameter formula

Page 3:  · Web viewπ/2 the x value is from length to 0. And similar to the X axis, at Y axis I also can find the relevance to R. So if we want paint a point of coordinate in output image

E: I + k*n = (p + k*(x-p) , q + k*(y-q) )4. This point is must on the circle, so its distance from the circle center is right r. r = √(Ex−Ox)2+(Ey−Oy )2

5. Then we can get a polynomial of k.

6. Solve it by x=−b±√b2−4ac2a

, and we only have to concern the point in the image,

thus the solution must be positive.

After we get two side of the edge, we could know the length between two edge point.Assume it is “L”

Then we back to see the point we want to find value.Count its lx and ly .lx = √(x−Ex )2+( y−Ey )2

ly = √( p−0)2+(q−0)2

Find the ratio and mirror to the original imagerx = lx / lry = ly/√2r

(x,y) = (length * rx , width *(1- ry)) (minus 1 is for that I want to let the image floor is still down)

B. Print out the original image

C. Print out of output image

Page 4:  · Web viewπ/2 the x value is from length to 0. And similar to the X axis, at Y axis I also can find the relevance to R. So if we want paint a point of coordinate in output image

(left A) (right B) (right C)

Page 5:  · Web viewπ/2 the x value is from length to 0. And similar to the X axis, at Y axis I also can find the relevance to R. So if we want paint a point of coordinate in output image

(The whole image)D. Discussion of the result

About the forward translation and the reverse translation:In this homework I didn’t use the forward translation. First, use forward translation means that I must do interpolation, and this would have more calculation and the miss would be more. Also, while we do the interpolation, we may not sure each point on the target image has the value to fill. Therefore, I choose the reverse translation.

Secondly, in this problem we have the other way to solve. The method is using some points and trying to figure out the translation matrix. By using this method, we need to choose at least five points that could form the right figure. Unfortunately, it’s too difficult to make sure that I have already done the inverse matrix right and choose the point to let the output image is right we want.

Thirdly, see the edge of this output image. Obviously, the curve edge is not smooth, on the contrary, it is seems like saw tooth. Enlarge the image, then we could discover this is because between the pixel which is valued and the white pixel it changes directly. Like this:

It is too sharp to let us uncomfortable.So, it we want this image more smooth, we could blur it by average the value of the edge pixel. However, it would change the data which we warped, so I didn’t keep the

Page 6:  · Web viewπ/2 the x value is from length to 0. And similar to the X axis, at Y axis I also can find the relevance to R. So if we want paint a point of coordinate in output image

step that blur the image.

PROBLEM 2 : MORPHOLOGICAL IMAGE PROCESSING

A. Method and motivation:When I do morphological processing of shrinking, thinning, skeletonizing, I adopt the approach of small filter. There are two stages of this approach, and in the processing detail depending on which application we do. The stage one we need to generate a binary image M(j,k) called conditional array. In this array I marked the candidate for erasure. When generating this array I use the looking up table, the method is like this:

for a mask M: [a1 a2 a3a4 a5 a6a7 a8 a9 ] we could count a unique value to present the

value. I take the formula: value = (a1*2 + a2*4 + a3*8 + a6*16 + a9*32 + a8*64 + a7 *128 + a4 *256) Then I create a table to save these masks by using a array mask[2+4+…+256]. mask[value] = 1, the mask is the LUT∴ bellow. After constructing the LUT, I started generating the M(j,k). I read the original image

data by a 3*3 matrix and counted it use the same formula of counting value. (We don’t need to counted the a5 because it must be 1 then we counted the whole matrix.) In this stage, if we hit the mask(the value calculated from the image in the LUT is 1), we marked it on the array M.

Done with the first stage, we get a binary image M. I need to build another LUT table for the second stage. This LUT is in order to avoid too many points to be erased. The mask at this stage is too more to list all due to it contains “A B C D”symbols. Here I was lazy to type all possible masks; hence I gave up using the LUT. I check the value of the mask and M bit by bit instead of the symbol D. (A B C use the flag to check it fit in with A B C =1) If the pixel M(J,K) hitting all ∪ ∪masks, we change the value of original data to 0.(This is for the white pixel shrink(or thin skeleton).) In conclusion, the method we do could present by this image.(G is the output image)

Page 7:  · Web viewπ/2 the x value is from length to 0. And similar to the X axis, at Y axis I also can find the relevance to R. So if we want paint a point of coordinate in output image

And for the effect presenting, I would show up for five iterations, ten iterations and the image converged. (The definition of convergence is no more pixel be erased.)

B. Print out the original image

C. Print out of output image#shrink

Page 8:  · Web viewπ/2 the x value is from length to 0. And similar to the X axis, at Y axis I also can find the relevance to R. So if we want paint a point of coordinate in output image

(5 iteration) (10 iteration) (Convergence #933 )

#Thin

(5 iteration) (10 iteration) (Convergence #16)

#skeleton

(5 iteration) (10 iteration) (Convergence #34)

d. Discussion of the resultDiscuss the difference between shrink, thin. After the 5~10 iteration, the image

Page 9:  · Web viewπ/2 the x value is from length to 0. And similar to the X axis, at Y axis I also can find the relevance to R. So if we want paint a point of coordinate in output image

generated is almost the same. At this time, we may confuse - Have we typed in the right mask? However, in fact, the thing of shrinking and thinning done is try to make the line to be only one pixel connected. When all the line is only one pixel connected, the thinning would stop here, nevertheless, the shrinking would not stop.

Shrinking would erase the pixel only connected to one pixel.Like this:

So, it would have point to be erase if there are points is at the line end. And when it is converged, it means that all point is have to connected neighborhood. By this conclusion, the image will be left only the dots or the cycles or a line both ends connected to the cycle.

※in the second problem, it just have a lot of masks to be typed in. Besides, it’s not an easy work, because we can’t make any mistake, or I will get the wrong answer and it’s hard to debug! Except this method, I have no idea of trying other methods to deal with this problem, so I have nothing can make a compare.

BONOUS: APPLICATIONA. Method and motivation:

a.) Clean the noise as much as possibleDue to I didn’t what the noise in the image. So I have to try each methods of noise cleaning I learned. First, I use the low-pass filtering, and the output image is :

(low-pass filter)

and the impulse method (the maxmin)

Page 10:  · Web viewπ/2 the x value is from length to 0. And similar to the X axis, at Y axis I also can find the relevance to R. So if we want paint a point of coordinate in output image

and the median method

But I think the white point is the noise, and I can’t erase it by these filter. So I check up the histogram. In the histogram, there are some points is informally light(value is close to 255). I remove it compulsory, at the threshold 140. Then I got the image like this.After got this image, then I start remove the noise. After doing all methods, I feel it’s hard to choose which one is better. Because, the image is more blur, then it with less noise. Finally, I use the hybrid of impulse and the uniform.(Do the minmax first, and then use the low pass filter.)

b.) Count the total number of cell bodies

Page 11:  · Web viewπ/2 the x value is from length to 0. And similar to the X axis, at Y axis I also can find the relevance to R. So if we want paint a point of coordinate in output image

In order to let the computer easy to count how many the cell bodies is, using the noise-cleaned image is the first step. This step could avoid the white points to be the cell bodies. Then, all things I have to do is think how to let computer this is a cell body. In the beginning, I tried to find the threshold of the pixel value of the cell bodies, so the following image is generated by the threshold 40.

It seems much easier to count.So, I choose the threshold is 40.The second problem is what is “a” cell body for computer.Then, in my view is the meaning of a cell body it may be an area with the value higher than the threshold.So, I check by the judgment of

a line like a mask. When the area of 5*5 square of the value is all higher than the threshold, then I would take it as a cell body. At this moment, a new problem we need to solve. When the computer get this image data, it just got a big array which record the pixel value presenting the image. While the computer process the step above, it must scan it pixel by pixel, however, we can’t enlarge or shrink the mask to hit the all cell bodies for each just one. So, when we hit a mask, then I erase the whole cell body by changing the pixel value. By using the recursive function, I let the area(like a lake in the image) to disappear right after it has been counted as a cell body. By this method, the computer counted the cell number is 50.

c.) Count the total length of all neuritisIn this problem, I think the edge detection method would be useful. By the second order of edge detection, we could get an image is much cleaning than first order. (first) (second order)

Page 12:  · Web viewπ/2 the x value is from length to 0. And similar to the X axis, at Y axis I also can find the relevance to R. So if we want paint a point of coordinate in output image

Therefore, I choose the second order one to do the next step.Because we want to count the length of the cell, I think that in real life if I want

to count a irregular figure’s length, I would use a cord to surround the object. Then I just take a ruler to measure the cord, I can know the girth of the object. And for the figure of neuritis, the girth is approximately equal to the length*2. But with this image the cell too thin to let the edge detection to separate into two parts. It is just like a line. So, for this problem, I think I can thinning the image(after this the line length would equal to the number of pixels), and then count how many pixel left. I think this answer would almost equal to the real answer which needs a difficult calculation.The image which I take to count the length:

The length of neuritis is 13718 pixels.

D. Discussion the resultDue to the noise effect, the answers of above aren’t absolutely correct. Besides, my methods are also with drawbacks. In the sub problem of b, I would probably change two cells to be one. For example, the position of image marked, actually, it’s two cell bodies without doubt. However, I would full the whole area when the mask hit the upper cell. Until know, I have no idea to solve this problem, also I can’t come up with the other better method to do with this question. And in the sub problem of c, I just count the pixel number and take it as the answer. There are a lot of errors in here. Firstly, some edge lines is broken when doing the zero crossing. And I don’t fix it. Oppositely, there are some point generated from the noise, and I don’t erase it also. It sounds like a lot of mistake I made. But I think these two errors could counteract with each other, then the answer should be more closely than just solving one part of this.

Page 13:  · Web viewπ/2 the x value is from length to 0. And similar to the X axis, at Y axis I also can find the relevance to R. So if we want paint a point of coordinate in output image

Readme file# DIP Homework Assignment #2# April 15, 2009# Name: 郭明鑫# ID #: b95902058# email: [email protected]# compiled on WINDOWS NT with gcc# the morphological processing is automatically stopped at convergence. all: compile prob1 shrink thin skeleton noise cell length

compile: gcc hw2_2.c gcc -lm hw2_1.c -o prob.exe gcc bonous.c -o bonous.exe gcc -lm bonous2.c -o bonous2.exe gcc hw2_3.c -o bonous3.exeprob1: ./prob.exe campus.raw apple.raw

shrink: ./a.out maze.raw shrink.raw shrinkthin: ./a.out maze.raw thin.raw thinskeleton: ./a.out maze.raw skeleton.raw skeleton

noise: ./bonous.exe cells.raw hicell.raw 1 140 ./bonous2.exe hicell.raw minmax.raw 10 ./bonous2.exe minmax.raw noiseclean.raw 3cell: ./bonous.exe noiseclean.raw inverse.raw 2 40 ./bonous.exe inverse.raw inverse.raw 5 40

length: ./bonous2.exe noiseclean.raw sec.raw 2 1 ./bonous3.exe sec.raw length.raw thin ./bonous.exe length.raw length.raw 4 40

Page 14:  · Web viewπ/2 the x value is from length to 0. And similar to the X axis, at Y axis I also can find the relevance to R. So if we want paint a point of coordinate in output image

clean: rm -f a.out rm -r *.bmp

By typing make it would automatically run the output we need.

And print out the converged times, the number of the cells and the length of neuritis.