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.

How to convert black holes on white background, so that I can see a binary image of holes on white image or bright dots on black image.

enter image description here

I can create a mask then also I am stuck with bright dot on black area, and then remaining white area.

 ms = ColorNegate[image]

enter image description here

share|improve this question
1  
A simpler way to create that mask would be ColorNegate. –  Pickett Feb 21 at 20:15
add comment

2 Answers 2

up vote 4 down vote accepted

ImageDifference[] is ideal for such a task:

i = ColorNegate@Import["http://i.stack.imgur.com/Eskg5.png"];
ImageDifference[DeleteSmallComponents[i, 30, CornerNeighbors -> False], i]

Mathematica graphics

share|improve this answer
    
I would argue that the key to this is not ImageDifference but DeleteSmallComponents which acts as kind of inverse top-hat transform. I.E. we need ImageDifference because DeleteSmallComponents does the opposite of what we want. –  Pickett Feb 22 at 0:47
    
@Pickett Ok, you can keep your key. I'll keep mine and everybody's happy :) –  belisarius Feb 22 at 0:58
    
I'm didn't feel happy/content when I read your comment because you make it sound like a matter of opinion. You don't even need ImageDifference, you might as well use e.g. ImageSubtract or ImageMultiply. And you don't even bother to explain why you think ImageDifference is "ideal" for this situation, when in fact it is not even necessary in the solution, which is based on DeleteSmallComponents? –  Pickett Feb 23 at 12:43
add comment

Using TopHatTransform:

img = Import["http://i.stack.imgur.com/TlMUh.png"];
TopHatTransform[img, DiskMatrix[5]]

tophat

Since you ask this kind of basic image processing question, I guess a good idea would be to read about morphological operations. A very nice practical book is the legendary Digital Image Processing by Gonzales & Woods. There you will learn that the top-hat transform is built up from more basic morphological operators. Therefore, all the next lines give the same result:

TopHatTransform[img, 3]
ImageSubtract[img, Opening[img, 3]]
ImageSubtract[img, Dilation[Erosion[img, 3], 3]]

Additionally, you should be aware, that morphological operations probably don't work in all circumstances. Then, belisarius' approach might be an alternative (and worth an upvote) as long as the components you want to extract are separated.

share|improve this answer
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.