- Reshape the image array to be a vector.
- Sort the vector in descending order.
- 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).
- Finally, reshape the vector of flagged indexes. This implicitly creates a mask, and you can freely decide how to use that mask.
Any tool/method to get top x% brightest pixels in image ?
16 views (last 30 days)
Show older comments
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.
0 Comments
Accepted Answer
John D'Errico
on 24 Feb 2019
Edited: John D'Errico
on 24 Feb 2019
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...
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.
More Answers (1)
zheng wu
on 22 Dec 2021
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
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!