Any tool/method to get top x% brightest pixels in image ?

13 次查看(过去 30 天)
I need any inbuilt method / process to find out top 5% brighttest pixels in a grayscale image. Getting their positions as mask or just isolating them by black/white and rest pixels with white/black color (thresholding) in that image. My aim is to find out lowest intensity value among those top 5% brightest pixels in the image.

采纳的回答

John D'Errico
John D'Errico 2019-2-24
编辑:John D'Errico 2019-2-24
You need to learn to think about how to use MATLAB. You don't need a specialized tool.
A grayscale image is just a 2-d array of numbers, probably scaled 0-255 or 0-1. Bright pixels are those closest to 1 (or 255). So...
  1. Reshape the image array to be a vector.
  2. Sort the vector in descending order.
  3. Flag the pixels you are interested in. to identify them. Remember the first pixel on that list is the brightest. The pixel at 5% will be near location round(numel(V)*0.05).
  4. Finally, reshape the vector of flagged indexes. This implicitly creates a mask, and you can freely decide how to use that mask.
Only you know how you would display those pixels. I would probably do it using a pseudo-color image. So I'd probably introduce a color that would indicate where those pixels were, shading the colors to indicate how bright they were.
Note that you need not do anything fancy here. For example, you do not need to convert your image to a domain like L*a*b*, or HSV, and then sort things on the appropriate channel, because brightness will be directly related to pixel value in a grayscale image, and all you care about is locating the brightest 5% of the pixels. A sort will be sufficient in any color remapping for that purpose.
Had you asked to find the pixels that were within 5% of the brightest pixel, perhaps in terms of luminance, that would be entirely different as a question.
Finally, you need to accept that 5% of the colors in a gray scale is a very small range. Color is not terribly finely discretized, generally just the integers 0-255, so 8 bit color. If 0-1, then it is generally a linear remapping of the integers 0-255. If your image is fairly bright, then you may have many white pixels. So the top 5% of the pixels in your image may be all purely white.
  1 个评论
MD AMIR SOHAIL
MD AMIR SOHAIL 2019-3-18
I did it in a similar way. Calculated histogram- Count of pixels in each intensity level. Found the minimum intensity level for which top x% (total_pixel*x/100 pixels) pixels belong. It was quite faster. And thanks for your help John D'Errico.

请先登录,再进行评论。

更多回答(1 个)

zheng wu
zheng wu 2021-12-22
Matlab has a function quantile to do this. Assume you have grayscale image I th = quantile(I(:), 0.95) will return the threshold to get 5% brightest pixels

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by