How to make the edge darker (increase contrast?)

I want to somehow increase the contrast if it is the thing to do. What I want is make the edge darker and clearer, so that I can detect it better in binary image. For example this is what I want:
But I made this through picture manager not MATLAB. How can I do this with matlab? If I use imadjust or etc for enhancing contrast, I get this:
which is not what I want. Now these are my questions:
1. How can I use MATLAB to get the second image? I do not know how to use imajust or imcontrast to do so.
2. Is my whole method good or efficient for my final purpose? (clearer edge in binary)?
Thanks so much Steven

 Accepted Answer

Increasing contrast with a point process like imadjust is not what you want to do. Just think about it - it won't change the shape of your edge, it will just make the threshold occur at a different value. You would need to do a spatial filter, something like mean shift or something like that. But to tell the truth I'm not sure you need to make the edge darker. What are you trying to measure exactly and then I can recommend an approach?

6 Comments

Could you kindly please explain about your suggestion?
What I want to measure finally is the accurate area of black region. what I am doing is turn it into binary, fill unwanted areas into black (that are wrongly white) and then compute the area using black pixels. But these edges are so important and should not be missed. Because of photography errors, they are not dark enough, so I have to make them darker to become visible in binary image.
What is you recommendation?
Thanks so much. Steven
Let's say you could threshold at 128 gray levels and get a binary image. But now you call imadjust, so whatever pixels were at 128 gray levels are now at some other gray level, say 90 or 150 or whatever. So then to threshold you'd just have to do it at 90 or 150 or whatever instead of at 128. And you'll get the exact same binary image. Exactly. Calling imadjust didn't do anything except increase contrast in the gray level image and change what threshold you need to use but you'd still get the same binary image. Just take the histogram and view it and you'll see what I mean. Imadjust just stretches the histogram and thus will change the threshold but the pixels in the foreground and the pixels in the background will be the same. There will be no pixels that are different.
I don't know what you mean by edges. I see a dark region and a bright region. I'm thinking that the edge is the interface between them but any pixel in that edge region will either belong to the dark or the bright region, not really to an edge per se. Unless you mean that little strip of slightly brighter edge at the top of the interface region, which is brighter than both the dark region and the bright region. You can get the pixels on the "inside" edge, which will be the dark pixels. You can get their value and their location. OR you can get the pixels on the "outside" edge, which will be the bright pixels. Which do you want?
Thanks again.
Yes. By edge I mean the interface between the darker region and bright region.
How do you think I can get them and in your opinion, what is the best way to find the area of the darker region (as I described my purpose above)?
Thanks so much!
If all you need is the area of the dark region then you don't need to find the edge at all. You just need to threshold and sum
binaryImage = grayImage < 128; % or whatever.
darkArea = sum(binaryImage);
darkArea2 = bwarea(binaryImage); % Another way using different algorithm.
If the binary image has some small clutter in it then you can remove that with bwareaopen().
Thanks.
Actually that is exactly what I meant. When I turn it into a binary, some area around the edge (interface) is lost, since it is not dark enough and it becomes white in binary, while in reality it should be dark. right?
That is why I asked for enhancing contrast. for example for the second image above (for which I made the interface a bit darker), the interface is captured in the binary image and apparently it is more accurate.
So my question was what to do in order not to lose interface data?
Thanks.
But contrast adjustment is not what you want to do. You can use bwareopen() to get rid of small clutter and noise in the binary image before summing. Or you can filter the grayscale image before thresholding with a sigma or knn filter, though that might alter the edge in a few locations.

Sign in to comment.

More Answers (1)

Play with the limits of imadjust. Test the following code and see how the image contrast changes with the limit values given to imadjust.
I = imread('pout.tif');
J = imadjust(I);
imshow(I),
figure, imshow(J)
K = imadjust(I,[0.4 0.6],[]);
figure, imshow(K)
K2 = imadjust(I,[0.2 0.8],[]);
figure, imshow(K2)

Asked:

on 16 Dec 2013

Edited:

on 26 Apr 2016

Community Treasure Hunt

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

Start Hunting!