% check the neighbourhood of the ambiguous pixels in order to assign them % to the appropriate cluster function ret = ambiguous_cluster(m) if (m(2,2))<0 [a,b]=hist(m([1:4 6:9]),length(unique(m))); if(length(unique(a(a~=0))))~=1 most_frequent_value=mode(m(:)); ret=most_frequent_value; else if(length(unique(a(a~=0))))==1 ret=m(2,2)*-1; end end end if (m(2,2))> 0 ret = m(2,2); end end