Message Boards Message Boards

4 Replies
0 Total Likes
View groups...
Share this post:

Background noise. How to find [x y] position?

Posted 10 years ago


I have a picture with some background noise: testbild2.jpg&userId=381930

If you look closely you will see some small white spots in the gray area. I want to find the [x y] coordinate to transform the value at this position to NaN (not a number).

Can you please help me to do this?

I already have a idea but it is not really working:

First I check which color is the most frequently. Assume my picture is named Pic:


In my case I will see that {0.5333,0.5333,0.5333} is the most frequently.

So I will pick this color from my list:

RealBackgroundColor = ImageData[Pic][[2]][[1]]

The colors of the entire picture I get with this:

AllColorValues = ImageData[Pic][[2]];

The color values for my noise I will then get with:

NoiseColor = Cases[AllColorValues , Except[RealBackgroundColor ]]

Now I know the color values of my noise so I can start to find the [x,y] position of this color:

PositionOfNoise = PixelValuePositions[Pic, NoiseColor[[1]]]

Now I know the position of my noise. I can replace it with the number NaN or (just to visually check) with black color:

ReplacePixelValue[Pic, PositionOfNoise -> 0.0]

But as you can see here, this method is to sensitive:

enter image description here

I already tried to work with Interval but this also doesnt really work.

In Matlab this problem was handled very easy by my friend:

[x y]=find(background>4.67e4)

What would you do?

Peter Parker

POSTED BY: Peter Parker
4 Replies

Good! happy to help...

POSTED BY: David Reiss

Hello David

Your answer was very helpful to me. The solution you have found is great and helps me a lot. I like the way how you used manipulate[]. Thank you very much, David!!!

Best reads,


POSTED BY: Peter Parker

By the way, you can find the locations in the image data via something like (for a threshold of 0.7):

Position[ImageData[image], _?(# > .7 &)]
POSTED BY: David Reiss

One problem with your approach is that you are setting your threshold above a fixed value corresponding to the one value at the beginning of your data. Your image does not correspond only to that value with a few other values well above it. Therefore you are seeing all values above your artificial threshold. Your friend's code (which I am not sure what it means exactly as it does not reference any image data and it seems to be looking for values above a threshold of 46700 which has nothing to do with your data...) seems to be looking for data above a threshold. And this is the approach that one would take here.

Let's assume that your image is called image. Then take a look at the following set of steps:

Here is a histogram of your data


Here are the actual data values:


And here are the values along with their frequencies:

{First[#], Length[#]} & /@ Split[Sort[Flatten[ImageData@image]]] 

So the question is where do you want to set your threshold for identifying your "outliers". One can argue from the previous result that the values above 0.7 are of interest to you. So let's identify them (resizing the result so that it is more readable):

ImageResize[Image[ImageData[image] /. {_?(# > .7 &) :> 1}], 600] 

And you can explore the threshold with a Manipulate.

 ImageResize[Image[ImageData[image] /. {_?(# > threshhold &) :> 1}], 600],
 {threshhold, .5, 1}] 

See the attached notebook...

I hope this helps.

POSTED BY: David Reiss
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
or Discard

Group Abstract Group Abstract