perform an erode on this with a 3x3 box of 1's 0 0 0 0 0 0 0 0 0 0 0 0 255 255 255 255 255 255 255 0 0 0 255 255 255 255 255 255 255 0 0 0 255 255 255 255 255 255 0 0 0 0 0 0 0 255 255 255 0 0 0 0 0 0 0 255 255 255 255 0 0 0 0 0 0 255 255 255 255 0 0 0 0 0 0 255 255 255 255 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Eroded: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 255 255 255 255 0 0 0 0 0 0 0 0 0 255 0 0 0 0 0 0 0 0 0 255 0 0 0 0 0 0 0 0 0 255 0 0 0 0 0 0 0 0 0 255 255 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ----------------------------------------------------- perform a dilate on this with a 3x3 box of 1's 0 0 0 0 0 0 0 0 0 0 0 0 255 255 255 255 255 255 255 0 0 0 255 255 255 255 255 255 255 0 0 0 255 255 255 255 255 255 0 0 0 0 0 0 0 255 255 255 0 0 0 0 0 0 0 255 255 255 255 0 0 0 0 0 0 255 255 255 255 0 0 0 0 0 0 255 255 255 255 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Dilated: 0 0 0 0 0 0 0 0 0 0 0 255 255 255 255 255 255 255 255 0 0 255 255 255 255 255 255 255 255 0 0 255 255 255 255 255 255 255 255 0 0 255 255 255 255 255 255 255 255 0 0 0 0 0 255 255 255 255 255 0 0 0 0 0 255 255 255 255 255 0 0 0 0 0 255 255 255 255 255 0 0 0 0 0 255 255 255 255 255 0 0 0 0 0 0 0 0 0 0 0 ====== Connected components algorithm on this: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 255 255 255 255 255 0 0 0 255 255 255 255 255 255 255 0 0 0 255 255 255 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 255 255 0 0 255 255 0 255 0 0 255 255 0 0 255 255 0 255 0 0 255 255 0 0 255 255 0 255 0 0 255 255 255 255 255 255 0 0 0 0 255 255 255 255 255 255 0 0 0 0 0 0 0 0 0 0 0 0 0 nextLabel = 6 join 1,2 3,4 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 0 0 0 2 2 1 1 1 1 1 0 0 0 2 2 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 3 0 0 4 4 0 5 0 0 3 3 0 0 4 4 0 5 0 0 3 3 0 0 4 4 0 5 0 0 3 3 3 3 3 3 0 0 0 0 3 3 3 3 3 3 0 0 0 0 0 0 0 0 0 0 0 0 0 go through again and look up each non-zero label and label it as the lowest number of the group so 2's relabelled to 1's and 4's relabelled to 3's all others stay the same col 0 1 2 3 4 5 6 7 8 9 row 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 1 1 1 1 1 0 2 0 0 1 1 1 1 1 1 1 0 3 0 0 1 1 1 0 0 0 0 0 4 0 0 0 0 0 0 0 0 0 0 5 0 3 3 0 0 3 3 0 5 0 6 0 3 3 0 0 3 3 0 5 0 7 0 3 3 0 0 3 3 0 5 0 8 0 3 3 3 3 3 3 0 0 0 9 0 3 3 3 3 3 3 0 0 0 10 0 0 0 0 0 0 0 0 0 0 end up with 3 connected components with labels 1, 3, 5 region with label 3 (the U shaped region) compute: area, centroid, perimeter (4-adjacency), perimeter length Consider the origin to be at top left pixel, increases to right for column numbers (0 to 9) and increases down for row numbers (0 to 10) area of region 3: 24 centroid row = (4*5 + 4*6 + 4*7 + 6*8 + 6*9)/24 = 7.25 col = (5*1 + 5*2 + 2*3 + 2*4 + 5*5 + 5*6)/24 = 3.5 perimeter contains 22 pixels length of perim = 20*1 + 2*sqrt(2) suppose three histograms: normalize them and then determine which of the h2 or h3 is closer to h1 using L1 distance maybe they are grade distributions: A B+ B C+ C D+ D F bin# 0 1 2 3 4 5 6 7 h1: 150 165 275 300 10 0 200 400 h2: 90 140 175 10 100 85 50 350 h3: 400 450 300 0 0 0 0 0 If you just had to choose, which distribution would you really say is closer to h1's --- h2 or h3? h1: 0.1 0.11 0.183 0.2 0.0067 0 0.133 0.267 h2: 0.09 0.14 0.175 0.01 0.1 0.085 0.05 0.35 h3: 0.348 0.39 0.26 0 0 0 0 0 l1(h1,h2) = .01 + .03 + .008 + .19 + .0933 + .085 +.083 + .083 = .5833 l1(h1,h3) = .248 + .28 + .077 + .2 + .0067 + .133 + .267 = 1.2117