DIP Assignment #1 Report

advertisement
DIP Assignment #1 Report
Name: Han-Ping Cheng
Department/Grade: CSIE 3rd
ID: B93902027
How to run my program:
1. My program is written by C language.
2. Compile and execute the program by README file:
command: make –f README
It will use the “boat256.raw” and “lena256_bright.raw” to be the input file of
problem1 and problem2 respectively by default. If you want to specify the input file,
you can type command “./solution1 <InputImageName>” for the problem1 and
“./solution2 <InputImageName>” for the problem2.
3. The output filename of problem1 is “resulta.raw”, “resultb.raw”, “resultc.raw”.
4. The output filename of problem2 is “linear.raw”, “bucket.raw”, “trans.raw”
and the corresponding hitogram filename is
“histo_linear.raw”,”histo_bucket.raw”,”histo_trans.raw” respectively.
The input histogram filename is “histo_input.raw”
5. Delete object files:
command: make clean –f README
6. Delete all output files include object files:
command: make cleanAll –f README
Following is the content of my README file:
# DIP Homework Assignment #1
# March 22, 2007
# Name: Han-Ping Cheng
# ID #: b93902027
# email: b93902027@ntu.edu.tw
# compiled on linux with gcc
CC=gcc
LN=gcc
All: prob1 prob2
prob1:
@echo "Problem1"
@echo "compiling and linking the code"
$(CC) -c hw1_prob1.c
$(LN) -o solution1 hw1_prob1.o
@echo "running the program,usage: solution1 inputImageName"
./solution1 boat256.raw
@echo "outputImageName: resulta.raw resultb.raw resultc.raw"
prob2:
@echo "Problem2"
@echo "compiling and linking the code"
$(CC) -c hw1_prob2.c
$(LN) -o solution2 hw1_prob2.o
@echo "running the program,usage: solution2 inputImageName"
./solution2 lena256_bright.raw
@echo "outputImageName: trans.raw bucket.raw linear.raw"
@echo "histogram: histo_input.raw histo_trans.raw histo_bucket.raw
histo_linear.raw"
clean:
rm -fr hw1_prob1.o hw1_prob2.o
cleanAll:
rm -fr hw1_prob1.o hw1_prob2.o result* histo_* trans.raw bucket.raw
linear.raw
About my program:
PROBLEM1: IMAGE RESIZING
(a) Down-sample the image and threshold it to a binary image.
Approach:
Use four pixel value (gray-scale) of original image to calculate the mean and
become the corresponding one pixel value of output image.
Ex: (aij is gray-scale)
(original image’s four pixel value)
(corresponding output image’s pixel value)
Then, use trial and error method to obtain the threshold. For this case, I choose 120 to
be the threshold value which would make the sky of image look neatly.
Result:
Original image:
(a) boat256.raw
Output image:
(b) resulta.raw
Discussion:
About the threshold value, my strategy is to make the sky of image look neatly,
because I consider the boat is the point of the whole image. The image of sky will
confuse the looker when there is only binary gray-scale, so I choose the threshold
value 120 which just fits my strategy.
(b) Up-sample the image and use reverse function to make it negative.
Approach:
Use four pixel value of original image to obtain the corresponding nine pixel
value of output image.
Ex: (aij is gray-scale)
(original image’s four pixel value) (corresponding output image’s nine pixel value)
Then, use reverse function ( y = 255 - x ) to calculate final output image’s pixel value.
Result:
Original image:
(a) boat256.raw
Output image:
(b) resultb.raw
Discussion:
The reason I use the mean of original image’s pixel value to be the new pixel
value of output pixel is that I hope there can be less differences between each two
adjacent pixels at the same time. Surprisingly, the result is better than I expected.
(c) Combine the original image and the resultant two images of step (a) and (b).
Approach:
Let the F(j,k) be the same as the pixel value of result(a) if 0 ≦ j ≦127, 0 ≦ k
≦127 and be the same as the pixel value of original image if 128 ≦ j ≦255, 128 ≦
k ≦255 and be the same as the pixel value of result(b) if 256 ≦ j ≦383, 256 ≦ k
≦383.
Result:
Original image:
(a) boat256.raw
Output image:
(b) resultc.raw
PROBLEM2: IMAGE ENHANCEMENT
Original image:
(a) lena256_bright.raw
(b) lena256_middle.raw
(c) lena256_dark.raw
(b) lena256_middle.raw
(c) lena256_dark.raw
Histogram:
(a) lena256_bright.raw
P.S. Vertical axis of histogram here is number of pixel (0~4096) while horizontal axis
is gray-scale (0~255).
(1) Contrast Manipulation:
Approach: (linear scaling and clipping method)
First, I count the pixels of each gray-scale(0~255) to obtain histogram, then find
the lower bound of the gray-scale where the pixels of each gray-scale is zero if the
gray-scale < lower bound, and find the upper bound of the gray-scale where the pixels
of each gray-scale is 255 if the gray-scale > upper bound. Then use the lower bound
and upper bound to do the clipping and obtain the linear function.
Ex:
Result:
Output image:
linear.raw
Histogram:
histo_linear.raw
(The result of three image: lena256_bright.raw, lena256_middle.raw,
lena256_dark.raw are the same by this method.)
Discussion:
The reason I choose the linear linear scaling and clipping method is that the
histogram of problem2’s input cases are all centralized in some range. So I can ignore
the gray-scale which has not ever appeared and do the linear transformation to map
the original narrow range to the widest range (0~255) which enhances the contrast of
the image.
(2) Histogram Equalization:
Approach1: (Transfer function method)
Step1: Count the pixels of each gray-scale (0~255) to obtain histogram.
Step2: Use the histogram to obtain the CDF.
Step3: Make the map-table which can map the CDF of original image’s gray-scale to
the CDF of uniformly distribution to find output gray-scale.
Step4: Use the map-table of step3 to map the original image to the output image.
Ex:
Result:
Output image:
trans.raw
Histogram:
histo_trans.raw
(The result of three image: lena256_bright.raw, lena256_middle.raw,
lena256_dark.raw are the same by this method.)
Discussion:
This method use the probability characteristic to map the original narrow range
of gray-scale to the widest range of gray-scale (0~255), and because the output
gray-scale is original cumulated density function multiply constant 255 (as show
above: x’= y*255), the new relative value of gray-scale is depend on its appear times
in original image. That is, in addition to make the original gray-scale more uniformly
distributed, this method can enlarge the contrast of the gray-scale of more appear
times and the gray-scale of less appear times which may do something help to show
the detail at the same time, so I consider the Transfer function method as one of
wonderful approaches.
Approach2: (Bucket filling method)
Accumulate the pixels of each original gray-scale to make the output image’s
each gray-scale has equal number of pixels (256), so the output image’s gray-scale
become uniformly distributed.
Ex:
Result:
Output image:
bucket.raw
Histogram:
histo_bucket.raw
(The result of three image: lena256_bright.raw, lena256_middle.raw,
lena256_dark.raw are the same by this method.)
Discussion:
Bucket filling method forces the gray-scale of original image to be uniformly
distributed, so it also makes the original narrow range of gray-scale to the widest
range of gray-scale (0~255) and enhances the contrast of image. But bucket filling
method does not always have such a good performance, if the image’s gray-scale is
centralized to some value and the pixels with the same gray-scale scatter over the
whole image, then the result might be distortion. In the input case of problem2, the
result looks as good as Transfer function method.
Conclusion of problem2:
In problem2, I use one contrast manipulation method : “linear scaling and
clipping” and two histogram equalization methods : “transfer function” and “bucket
filling”, because I consider the three methods as the best solution for the given input
case.
For contrast manipulation, the reason I use the “linear scaling and clipping”
method instead of “power law” or “amplitude-level slicing” and so on which we
learned in class is that I hope the detail of whole image can be observed rather than
just emphasize on some part.
According to the result of contrast manipulation and histogram equalization,
there are some differences. The image of contrast manipulation looks more smooth
(like real image) but has less details whereas the image of histogram equalization
looks less smooth but has more details relatively. I think it is because their different
concept of image enhancement. Contrast manipulation is just scaling some part of
original gray-scale, so the output histogram is look more like the original histogram
and isn’t likely to be distorted. On the other hand, histogram equalization is to make
the original gray-scale more uniformly distributed. To approach the object, Histogram
equalization will unavoidably distort the original image by modifying the histogram
but it may be tolerable for human’s percept. As the output of problem2, the image
output by whatever method— transfer function or bucket filling method—is still very
beautiful and can also see more detail.
Finally, thank you for reading my report patiently, the assignment really give me
a wonderful experience and let me acquire more sense about DIP.
Download