Grouping the pixel having same values

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 Kommentar

Image Analyst
Image Analyst am 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?

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

Andrei Bobrov
Andrei Bobrov am 23 Aug. 2012
Bearbeitet: Andrei Bobrov am 23 Aug. 2012

0 Stimmen

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 Kommentare

wen displaying as imshow(out) i get error
Error using iptcheckinput Function IMAGEDISPLAYVALIDATEPARAMS expected its first input, I, to be one of these types:
double, single, uint8, uint16, uint32, int8, int16, int32, logical
Instead its type was cell.
Walter Roberson
Walter Roberson am 29 Aug. 2012
Please show class(out) and size(out) when the error occurs.
class(out) is cell
and size(out) 49 2

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by