Digital Image Processing
(Spring 2013)


Assignment-3    

    You are developing a text recognition software, which aims at recognizing the text from a picture taken by a mobile phone. Before conducting any  recognition operations, it is better for you to finish some pre-processing job, one of them is to convert the gray level image (left) to a binary image (right), as following 

         

    This seems to be very easy. In this case, you only need to find a threshhold value and make all pixels  less than the threshhold as 0, and make the other pixels as 255.

    Then a problem arises, how to find the threshhold? Here we provide an iterative optimal threshold algorithm to automatically find a threshhold T:
1. Estimate value of T (start with mean)
2. Divide histogram into two regions, R1 and R2 using T
3. Calculate the mean intensity values 1 and 2 in regions R1 and R2
4. Select a new threshold T = (1 + 2)/2
5. Repeat 2-4 until the mean values 1 and 2 do not change in successive iterations

    Your first task is to implement the above method as function optimal_thd.m

    Enough? We hope so but situation seems more complex than we expected. In some case, even with the optimal threshhold, you can hardly get a satisfactory result, as showed in the following image. There is a shadow of hand as well as the mobile phone in the picture, and in fact you can not get a good result using any threshhold. It may remind you to do some pre-processing for optimal_thd.m, that's your second task, i.e., implementing the function preprocess_for_opthd.m. (Hint: using frequency domain operations)

                                         
                                                                               

    Requirement
          1. Complete the function  optimal_thd.m.
          2. Complete the function  preprocess_for_opthd.m.
          (All the materials can be found in Download section)

    Limitations
       None.

    Download
           1. Code
           2. Sample input image.

    Sepecification of submission
           1. Submission directory: ftp://lamda.nju.edu.cn/dip13/ass3
           2. The format: A zip file, which has the structure as: (--x means a directory named as x)
                    xxx.zip
                        --code:  optimal_thd.m, preprocess_for_opthd.m
                        --doc:  a pdf/doc file which describes the idea, method and implementation in your experiment. 
                Here we provide a sample submission file. (Your submitted file should be organised as the same structure as this file)
           3. Use your student number as the name of the submitted file, such as b111221001.zip. If you have multiple submissions, add an extra '_' with a number, such as b111221001_1.zip. We will use the the version with the largest number as your final submission.

    Tip
    You can write a matlab script (for example, test_ass3.m) to test your code. This script need not to be submitted, and is like
       File:  test_ass3.m
        ---------------------------------------------------------------
         % load a image
I = imread('paper.jpg');

% pre-processing
I_pre = preprocess_for_opthd(I);

% get binaray image
I_bin =  optimal_thd (I_pre);

% show results
subplot(1,3,1);
imshow(I);
subplot(1,3,2);
imshow(I_pre);
subplot(1,3,3);
imshow(I_bin);
----------------------------------------------------------------