Grouping the pixel having same values

16 views (last 30 days)
I have a RGB image in which i have taken some pixel values for example
83 81 81 84 85 84 82 82 84 81 83 83 81 81
83 81 81 83 83 82 80 81 83 80 82 83 81 79
81 79 83 84 84 84 81 81 82 80 81 81 79 79
79 80 82 86 85 84 83 83 85 85 81 81 79 79
79 81 84 85 85 83 83 83 84 83 81 83 81 81
84 83 84 85 85 83 84 80 81 81 81 82 82 83
83 84 86 85 85 83 84 80 79 80 82 82 81 83
for exmaple first value is 83,neighbour value is also 83 so it must be grouped(2 values will be grouped),next value 81(4 values of 81 it must be grouped )then next value is 85 there is no other neighbour value of 85 so it must be grouped as single vaue(1 value will be there),please help how to process
the pixel having same neighbour values must be grouped
please help
  1 Comment
Image Analyst
Image Analyst on 23 Aug 2012
Define grouped. The bwconncomp or bwlabel function will do connected components labeling, but then what are you going to do with, say, 256 images of the groups?

Sign in to comment.

Accepted Answer

Andrei Bobrov
Andrei Bobrov on 23 Aug 2012
Edited: Andrei Bobrov on 23 Aug 2012
I =[83 81 81 84 85 84 82 82 84 81 83 83 81 81
83 81 81 83 83 82 80 81 83 80 82 83 81 79
81 79 83 84 84 84 81 81 82 80 81 81 79 79
79 80 82 86 85 84 83 83 85 85 81 81 79 79
79 81 84 85 85 83 83 83 84 83 81 83 81 81
84 83 84 85 85 83 84 80 81 81 81 82 82 83
83 84 86 85 85 83 84 80 79 80 82 82 81 83 ];
d = unique(I);
out = [];
for jj = 1:numel(d)
r = bwconncomp(I == d(jj),4);
out = [out;[repmat({d(jj)},r.NumObjects,1) r.PixelIdxList']];
end
or
d = unique(I);
out = [];
for jj = 1:numel(d)
s=regionprops(bwconncomp(I == d(jj),4),'PixelList');
out = [out;[repmat({d(jj)},numel(s),1) {s.PixelList}']];
end
[ii,ii] = sortrows(cell2mat(cellfun(@(x)x(1,:),out(:,2),'un',0)),[2 1]);
out = out(ii,:);
  3 Comments
Walter Roberson
Walter Roberson on 29 Aug 2012
Please show class(out) and size(out) when the error occurs.
kash
kash on 29 Aug 2012
class(out) is cell
and size(out) 49 2

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!