Categorise pixel gray values?
Info
This question is closed. Reopen it to edit or answer.
Show older comments
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
Answers (2)
Jan
on 4 Jul 2011
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);
1 Comment
Andrei Bobrov
on 4 Jul 2011
+1
Andrei Bobrov
on 4 Jul 2011
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 Comments
Jan
on 4 Jul 2011
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
on 5 Jul 2011
@Jan, agree with you
This question is closed.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!