Categorise pixel gray values?

I need to be able to categorise pixel grayscale values for an ROI. The image is a 8-bit image (so 0-255). I want to categorise pixel according to their intensity, eg 0-50, 51-100, 101-150 etc... Then to be able to calculate the percentage in each category and then map the pixels to the categories into a colour and create a new image. Any help would be great! Thanks
Richard

답변 (2개)

Jan
Jan 2011년 7월 4일

2 개 추천

What did you try and where exactly is the problem?
What about a simple devision?
Im_uint8 = uint8(rand(100, 100) * 256);
Im_categ = fix(double(Im_uint8 - 1) / 50) + 1;
% 0-255 -> 1:6
% Be aware that the the 6th bin contains 251:255 only
Now create a map with 6 colors and create an RGB image:
map = [0,0,0; 0.5,0,0; 1,0,0; ...
1,0.5,0; 1.0,1,0; 1,1,0.5];
RGB = ind2rgb(Im_categ, map);
image(RGB);
Andrei Bobrov
Andrei Bobrov 2011년 7월 4일

0 개 추천

my variant ( EDIT )
A = randi(255,10);
x = 0:51:255;
x(end) = x(end)+100*eps;
[n nb] = histc(A(:),);
B=A;
B(:)=nb;

댓글 수: 2

Jan
Jan 2011년 7월 4일
0:51:255 sets one limit to 102, but the OP wanted "0-50, 51-100, 101-150". But your 51 elements per bin seems to be more logical. I'd set the last limit to 256, otherwise the 255 get's it own bin.
Andrei Bobrov
Andrei Bobrov 2011년 7월 5일
@Jan, agree with you

이 질문은 마감되었습니다.

질문:

2011년 7월 4일

마감:

2021년 8월 20일

Community Treasure Hunt

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

Start Hunting!

Translated by