|
On Fri, 28 Aug 2009 15:11:03 -0400, Frank Chang <etaghtron@gmail.com>
wrote:
> Hi group,
>
> I have a question regarding a quite unusual array operation which has
> puzzled me for a few days. I cannot come up with a reliable solution.
> I'd like to hear your thoughts.
>
> The problem can be described as follows.
>
> If I have a 2D array, all elements of which are real numbers. I'd like
> to keep a certain percentage of the pixels whose values are high, and
> change all the others to zero. For example, if the original array is
> like this
>
> [ 4, 5, 6
> 7, 8, 9
> 1, 2, 3]
>
> And I'd like to keep 20% of the pixels whose values are higher than
> the rest. The converted array becomes
>
> [ 0, 0, 0
> 0, 8, 9
> 0, 0, 0].
>
> I should note that the matrix has uncertain dimensions, and the
> percentage I'd like to keep is really case by case. I thought
> histogram might be the best way to do this. But I simply could not get
> it to work... Could you please shed me some light? Thank you!
>
> Best Regards,
> Frank
The simple part, once you find the threshold you can set the ones below it
to 0 using logical idexing:
image( image<Threshold) = 0;
To find the Threshold, you could either
-use SORT (if your image is small enough). Convert you percentage measure
to an index. Example, top 20% would mean use value at index 9 for the
Threshold for am image with 10 pixels.
-If you know before hand, the range of the data, you might be able to
devise some heuristic measure to obtain the Threshold
-am sure there are more.. :)
Note: What should happen when there are repeated pixel values?
|