How to count precisely proportion of some small pane in a electron microscope picture by it "Area"
I'm not 100% sure what you want. Loosely speaking, your images look like there are hills and valleys, with light coming from the left. And I think you're looking for the "valleys" in that landscape.
A mathematical model for this would be: There's a "height" (or "depth") for every pixel, and the image you have is the gradient (in X-direction) of that height field. So we want to find a height field, that, when convolved with a gradient filter kernel, reproduces your source image.
(this plot shows one line of the input and result images below)
This problem is called "Deconvolution", and Mathematica has a built-in function for it: ImageDeconvolve
.
Let's try this with one of your images:
urls = {"http://i.stack.imgur.com/LiQsY.jpg",
"http://i.stack.imgur.com/CRkrS.jpg",
"http://i.stack.imgur.com/cXTRq.jpg",
"http://i.stack.imgur.com/KUcKE.jpg",
"http://i.stack.imgur.com/OO36H.jpg"};
img = ImageTake[ColorConvert[Import[urls[[1]]], "Grayscale"], 500, 500];
I'm using a derivative of Gaussian filter kernel for the deconvolution, and (determined by trial and error) the "Wiener" method:
deconv = ImageAdjust@
ImageDeconvolve[img, GaussianMatrix[3, {0, 1}], Method -> "Wiener"]
This doesn't look too impressive, but if you binarize it (default threshold, no manual tinkering needed):
HighlightImage[img, Binarize[deconv]]
You see that we get a pretty good estimate for the "hills". Getting the "valleys" is just as easy:
HighlightImage[img,
Erosion[ColorNegate[Binarize[deconv]], DiskMatrix[5]]]
Here's the result for the full images:
Monitor[
Do[
img = Image[ColorConvert[Import[urls[[i]]], "Grayscale"],
ImageSize -> 1280];
deconv =
ImageAdjust@
ImageDeconvolve[img, GaussianMatrix[3, {0, 1}],
Method -> "Wiener"];
Export["so_Valleys" <> ToString[i] <> ".jpg",
HighlightImage[img,
Erosion[ColorNegate[Binarize[deconv]], DiskMatrix[5]]]]
, {i, Length[urls]}], i];
In the next two images, some of the "valleys" are brighter than the others, so the "brightness is gradient of height" model results in "slanted" areas: That's why these valleys are slightly larger on one side
This is kinda slow in my mac so before spending more time on it I rather have some comments from OP.
The basic idea is that I want to amplify the gradient on the image and then separate the areas of constant value.
img = Import["http://i.stack.imgur.com/LiQsY.jpg"]
img2 = Import["http://i.stack.imgur.com/OO36H.jpg"]
xx2 = Module[{im = ImageTake[img, {800, 400}, {400, 800} ]},
ImageAdd[im, GaussianFilter[GradientFilter[ImageAdd[im,
GaussianFilter[GradientFilter[im, .5], 0]], .5], 0]]]
I don't know how to explain this but seems to work. I want to add noise to the areas where there is a lot of variation so I can separate better later.
Now I want to have the image in colour, since looks nicer and gives me the sense of height.
colorImg =
ListContourPlot[ImageData[xx2, DataReversed -> True],
ColorFunction -> Hue, Contours -> 5, Frame -> False,
AspectRatio -> 1, ImageSize -> 401]
It's starting to look like something. Now color separate
ColorSeparate@colorImg
For the large "ponds" of the other picture you need to take another channel btw.
GaussianFilter[%[[2]], 3]
Binarize[%, .95]
And finally check it out.
HighlightImage[ImageTake[img, {800, 400}, {400, 800} ], %]
You may need to get some reference images to check how much we are understatimating due to edge thickness. It also looks like your tip is bent in the microscope, there is this "shadow" to the left...
To improve the quality maybe it would be nice to star form the clusters I found and increase them till they touch a boundary. I imagine this as a landscape and you want to pour ink on the lagoons. Looks fun.