Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I have a question regarding colouring and binary image filtering, but unfortunately, the system doesn't permit the inclusion of images for first-timers. If anyone would like to see the images described below, please email me directly.

I have an image of gold electrodes on a flat substrate obtained with a scanning electron microscope. I would like to colour in all the gold electrodes and particles that appear in the centre of the image, leaving the colour of the background as it is for now. I perform straightforward routines by implementing the following code: Firstly, I rename the image q: q=Image; Then I apply the PeronaMalik Filter to enhance the edges and diffuse the background:

pq = PeronaMalikFilter[q, 20, 0.02, 2]

The background in the image thus obtained looks more diffused and uniform, while the edges of the gold electrodes and particles appear sharp, in contrast to the background. Then I give the following command to colour in the gold

goldq = ImageApply[# {1., 0.843104, 0.} &, q, 
  Masking -> SelectComponents[Binarize[pq, 0.36], "Area", # > -300 &]]

The result is an image in which the gold electrodes are almost entirely coloured in gold, but there are also large regions that are coloured by gold, which shouldn't be; for instance, the left side of the image, and the top right and bottom right. It seems that these areas receive colour due to the fact that they have the same binary level as the actual gold electrodes, which is an artefact of the scanning, and should definitely have the same zero level as the rest of the background.

Is there any way to correct this gaffe digitally using Mathematica's built-in functions? Is it possible, additionally, to give the background a different colour?


As suggested, here are all three images:

Original image: original image After filter: After filter After gold: After gold

share|improve this question
    
Thank you very much for your comments and suggestions. I apologize for a small error. As you can plainly see, the first image is not related to the next two images. I inadvertently attached the wrong original image. Here is a link to the original image As to your suggestions, when I look at the resulting image that you give (top, single), I observe two grey patches in the top of the electrode, and the additional particles to the right of the electrode have not been colored. –  user2445 Sep 27 '12 at 14:51
    
(the rest of Gideon's comment) "As for the suggestions of a different method of binarizing, again I can spot patches of grey where only gold should be, particularly at the center of the image. I could be mistaken, but I think that it is not so simple to color in everything just right, which is what I looking for." –  J. M. Sep 27 '12 at 14:58
add comment

3 Answers 3

I think there is something wrong in your code. Why did you write # > -300 & as criterion for the area. Lets try another approach with only a simple gaussian filter:

img = ImagePad[
   ColorConvert[Import["http://i.stack.imgur.com/GdtlA.jpg"], 
    "Grayscale"], {{0, 0}, {-100, 0}}];
ImageApply[# {1., 0.843104, 0.} &, img, 
 Masking -> 
  Closing[SelectComponents[Binarize[GaussianFilter[img, 5], 0.464], 
    "Area", # > 1000 &], 3]]

Mathematica graphics

share|improve this answer
add comment

You could try another binarizing function. For example:

mask = MorphologicalBinarize[pq, {.5, 0.6}]
GraphicsRow[{mask, 
 ImageApply[# {1., 0.843104, 0.} &, q, Masking -> mask]}, 
 ImageSize -> 500]

image of two gold things

share|improve this answer
add comment

The way of adding colors to the SEM image is presented here http://youtu.be/IsUW6d1U2yM

share|improve this answer
5  
Hello, and welcome to our site. Link-only answers are discouraged, as if the link fails the answer becomes useless. Could you summarize the content that is linked to in the answer itself? Also, can you cite a reference that the manual ("paintbrush") coloring shown in the video is the industry standard, if that is in fact what you're claiming? Personally I would expect it to be a somewhat more sophisticated combination of automated segmentation and manual adjustment. Incidentally, the manual-only method falls outside the topic of our site unless it can be tied to Mathematica somehow. –  Mr.Wizard Jun 5 at 10:38
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.