0

I have implemented Niblack thresholding onto an image in MATLAB (R2014B) as such:

function [ ] = processing_local( )

    x = imread('HW8.png');

%   Resize the image.  
    size(x);
    x = imresize(x,[500 800]);

    figure;
    imshow(x);
    title('Original');

    x = imadjust(x, [0.2,0.8],[0.5,1.0]);

%   HSV plane, extracting the value part.
    z = rgb2hsv(x);       
    v = z(:,:,3);
    v = imadjust(v);

%   Finding the mean and standard deviation.  
    m = mean(v(:));
    s = std(v(:));
    k = -.4;
    value = m+ k*s;
    temp = v;

%   Niblack  
    for p = 1:1:500
        for q = 1:1:800
            pixel = temp(p,q);
                if(pixel > value)
                    temp(p,q)= 1;
                else
                    temp(p,q)= 0;
                end
         end
    end

    figure;
    imshow(temp);
    title('Niblack Result.');

    end

The result I see is this:

Output of Niblack thresholding

As shown there is a lot of dark spots where the image has been degraded, how would I optimize this in MATLAB?

I would like to try to some uniform brightness but cannot implement this within the function. I have wrote it in a separate function like this:

function [ ] = practice_white( )

        x = imread('HW4.png');
        x = rgb2gray(x);

        background = imopen(x,strel('disk',15));

        white = imclose(x, background);
        whiteAdjusted = x ./ (white)*0.85;

        BW = imbinarize(whiteAdjusted, 0.2);

        figure
        imshow(BW); title('Test');

    end
Jay
  • 49
  • 1
  • 8

0 Answers0