Question

I have the following image (it's a license plate) and it was affected by salt and pepper noise of 0.9 probability (each pixel had 90% chance to turn completely white or completely black). I need to clean it as best as possible inorder to nmake the number readable. I have the basic allowed algorithms in Python but changes are allowed - and I need to somehow make the image clear. We turn the image into a black and white bitmap of pixels that are loaded into a matrix and we perform all the algorithms directly on the matrix. We use 2 variations of medians - I have tried many combinations of them both to no avail - no clear picture was produced. I desperately need help!

The code and the image are in this location in skydrive: http://sdrv.ms/1az6sRC in order to use the code Python 3.2 is nessesary and the add-on in the directory needs to be installed in order to present images in Python. The class matrix needs to be imported, and the file cleaning.py with the function clean contains my attempts - this function can use any of the code in the file (with variations) in order to achieve as good as possible result.

Any help will be appreciated.

Was it helpful?

Solution

Traditional salt and pepper image de-noising filter are suited when the noise probabilty is say about 40% (the probability of an image pixel being flipped). In your case, you have a density noise. You will need to use a computationally more expensive median-based filter to solve the problem. On closer looks at the results of this paper , it seems achievable, but you will need to implement it.

OTHER TIPS

Median filter solves salt and pepper problem but produce blurred image . To solve salt and pepper problem and preserve the original photo you must use Alpha Trim Filter . The Filter Idea :

1- Place a window over element

2- Pick up elements

3- Order elements

4- Discard elements at the beginning and at the end of the got ordered set (according to alpha input value)

5- Take an average — sum up the remaining elements and divide the sum by their number.

You can use matlab to implement it .There is a lot of previously implemented alpha trim filters you can use it and link your python program with matlab

Excuse me about dealing with python because my background about it is not very will

Hi you can use median filter or Max filter since you have 90% noise. Please refer the below code its in C++ but you can easily relate it to python . //maxOrmedian = True/False, inputImage = std::vector , kernalSize = 3, width = 256, height= 256 //

 std::vector<double> medianFilter(bool maxOrmedian, std::vector<double> inputImage, double kernalSize,int width, int height)
    {
       /* Fill all the values to output image */
       vector<double> outImage = inputImage;
      for(int y = kernalSize; y < height - kernalSize; y++)
      {
         for(int x = kernalSize; x < width - kernalSize; x++)
         {
           std::vector<double> tempList;
           for(int i = - kernalSize; i <= kernalSize; i++)
             {
               for(int j = -kernalSize; j <= kernalSize; j++)
                 {
                   double pixelValue = inputImage[(y+j)*width + (x+i)];
                   tempList.push_back(pixelValue);
                 }
             }
            std::sort(tempList.begin(),tempList.end());
            double newPixelValue = 0;
            if(maxOrmedian) //median filter
               newPixelValue = tempList[tempList.size()/2];
            else
               newPixelValue = tempList[tempList.size()-1];
            outImage[y*width + x] = newPixelValue;
          }
       }   
      return outImage;          
     } 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top