redChannel = IM(:, :, 1);greenChannel = IM(:, :, 2);blueChannel = IM(:, :, 3);for yourNumber = 1 : max(labelimg(:)) thisLabel = labelimg == yourNumber; % for example 2 or 3 or whatever region you want.
meanR(yourNumber) = mean(redChannel(thisLabel)); meanG(yourNumber) = mean(greenChannel(thisLabel)); meanB(yourNumber) = mean(blueChannel(thisLabel));endtable(neigbor label)= 2 3 4 5 2 1 3 1 1 4 1 1 1 5 1 0 1 1
I got a table which show the neighbor label and I got mean rgb for each label, I just need loop through the left triangle because another part is same.
The mean value for the label is double type, how I can round to integer only?
I got the mean of each label region and then I now want to compare them.
for i=2 : max(table(:))for j=2:max(table(:)) if(i,j+1)=1 %1 mean 2 label are neighbor
if compare(j+1,i)<=(rgb+-5) %then reassign the label
if (i>j+1) label i = label j+1 %always assign to smaller label
else label j+1 = label to i
Final result I hope to get is like this
label 4 and 5 is within(rgb+-5) with label 2 so all assign to label 2
label = 3 3 3 3 3 3 1 1 1 1 1 1 1 2 2 1 4 1 1 1 1 1 4 1 5 5 5 1 1 1 5 5 5 5 5 5 result = 3 3 3 3 3 3 1 1 1 1 1 1 1 2 2 1 2 1 1 1 1 1 2 1 2 2 2 1 1 1 2 2 2 2 2 2
Best Answer