Matlab image intensity level adjustment

I have a specific question to ask about the intensity adjustment for image processing. I need high constraint value to find small gaps in the image. I used a manual threshold value 0.99 to convert the grayscale image. However, as the illumination on the surface did not distribute evenly, some parts of the image is lost. I used adaptive method, however, the results is similar to a global threshold. Orignial picture:

Red point as intereted area:

Detail in Binary Image:

I0 = imread('1_2.jpg');
[R,C,K] = size(I0);
if K==1
    I1 = I0;
else
    I1 = rgb2gray(I0);
end
%Adjsut image to get a standar binary picture
%Adjust image intensity value
I1 = imadjust(I1,[0.1 0.7],[]);
BW0   = im2bw(I1,0.99);
    figure;
BW0   = bwareaopen(BW0,10000);
%Fill non_crack hole error
BW0   = bwareaopen(1-BW0,500);
BW0   = 1-BW0;
    imshow(BW0);

After this process, only half of the image will be left. I want a whole image with local intensity threshold which can show the same feature as the high-level threshold. What can I do?

Thanks

Answers (1)

You need to do a background correction to get rid of any lens shading. I attach a demo.

6 Comments

Hi
Thanks for the help after using the code you provide, the feature left as well.
I think it was treated as a background, is there any other suggestions?
Many Thanks
No, it didn't work well. It's considering both white and black things as the background. Let's try something else, a different way, actually a better way.
What you need to do is to get an image of a totally uniform image, like all gray or white. Then use polyfitn() to fix a polynomial and then divide the images. That will give an image like as if you didn't have any darkening of the image at the ends due to lens shading. Lens shading is normal but usually needs to be corrected for if you want a global threshold.
An alternative way other than dividing the image by the background is to try to flatten the field by using adapthisteq() but it's a bit tricky because you don't want to brighten the dark stuff in between your bright struts, so you'd probably have to use a large window size. Again, not as good an option.
Can you get an image from your camera of a plain, uniform background?
Not really. The technique I used to detect the crack is hough transform to extract line feature firstly, then along the line to find the dark gap. Is there any other suggestion may adjust intensity along the line? Then I may find the small gap some way.
Many Thanks
So, was there anything really wrong with your original binary image? The "detail" looked pretty good.

Not really, the problem is I have 5 different samples, this manual method may not find all the gaps sometime. I want to generate a universal way to find the location in some other image accurately. Here is another image:

This feature may not be that easy to detect.

Why not use a template - a reference image. Take a perfect version and get the perfect binary image. Then take your test image, call imregister() to align it, then binarize and subtract. Any defects will be super bright.

Sign in to comment.

Categories

Asked:

on 29 Apr 2017

Commented:

on 30 Apr 2017

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!