We selected the color value corresponding to the peak element of the
histogram of
2^18 color values. Calculating such an histogram requires:
(2^18)*sizeof(int) = (2^18) * (2^2) = 2^20 bytes = 1 MB memory
which is not very large but in order to reduce this number, instead
of calculating the maximum by creating the histogram we performed several
passes over the image and in each pass we count the number of several
color values. In every iteration a maximum value is found. The overall
maximum is the max. of these values. This process reduces the memory needed
by (1/n) for n passes.
After selecting the color of seed pixel, next step is finding an appropriate
place for the seed pixel. Choosing any pixel having the seed color would
lead some error because that pixel could be a noise. We consider the colors
of the neighbors of the candidate seed pixel as well. Pixels that fall
into the 21 X 21 frame (having the candidate seed pixel in the center)
are considered as neighbors.
While traversing a 21 21 frame over the entire image, we
take the difference of color value of each pixel in the frame and the seed
color value and sum these up. (The method of calculating the difference
is explained later.) We determine the pixel, which has the minimum value
of this sum as the seed pixel.
diff (( R1 ,G1 ,B 1),(R2,G2, B2 )) =sqrt( ( R1 - R2) ^2+ ( G1 - G2)^2
+ ( B1 - B2) ^2 )
| 1 | 0 | -1 |
| 1 | 0 | -1 |
| 1 | 0 | -1 |
| 1 | 1 | 1 |
| 0 | 0 | 0 |
| -1 | -1 | -1 |