3 using System.Collections.Generic;
31 width = binaryImage.width;
32 height = binaryImage.height;
34 this.a =
new Rect (a1.xMin* width, a1.yMin * height, a1.width * width, a1.height * height);
37 xHist =
new float[(int)a.width];
38 yHist =
new float[(
int)a.height];
40 Color[] c = binaryImage.GetPixels((
int)a.xMin, (
int)a.yMin, (
int)a.width, (
int)a.height, 0);
42 for (
int y = 0; y < (int)a.height; y++) {
43 for (
int x = 0; x < (int)a.width; x++) {
44 Color cp = c[y * (int)a.width + x];
46 xHist[x] = xHist[x] + cp.r;
47 yHist[y] = yHist[y] + cp.r;
63 int aMinX = (int)a.xMin;
65 for(
int x = aMinX; x< aMinX + xHist.Length; x++)
66 Debug.DrawLine (
new Vector3 ((x)*0.6f/width + 0.2f, 1.0f, -1),
new Vector3 ((x)*0.6f/width + 0.2f, 1.0f - xHist[x - aMinX]*0.2f/height, -1), Color.red, 30.0f,
false);
68 int aMinY = (int)a.yMin;
70 for(
int y = (
int)aMinY; y< (int)aMinY + yHist.Length; y++)
71 Debug.DrawLine (
new Vector3 (0.2f, (y + yOffset)*1.0f/height, -1),
new Vector3 (0.2f + yHist[y - aMinY]*0.2f/width, (y + yOffset)*1.0f/height, -1), Color.green, 30.0f,
false);
84 public List<KeyValuePair<int, float>>
findMin(
float[] hist){
86 List<KeyValuePair<int, float>> list =
new List<KeyValuePair<int, float>>();
88 for(
int i = 1; i<hist.Length-1; i++){
89 if(hist[i] <= hist[i-1] && hist[i]<= hist[i+1]){
90 list.Add(
new KeyValuePair<int, float>(i, hist[i]));
96 list.Sort(CompareValue);
111 public List<KeyValuePair<int, float>>
findMax(
float[] hist){
113 List<KeyValuePair<int, float>> list =
new List<KeyValuePair<int, float>>();
115 for(
int i = 1; i<hist.Length-1; i++){
116 if(hist[i] >= hist[i-1] && hist[i]>= hist[i+1]){
118 list.Add(
new KeyValuePair<int, float>(i, hist[i]));
123 list.Sort(CompareValue);
141 float clusterSize = 0f;
142 int clusterStart = 0;
145 List<KeyValuePair<int, float>> list =
new List<KeyValuePair<int, float>>();
147 for (
int i = 0; i<hist.Length; i++) {
151 if(f>0f && clusterSize == 0f){
161 if(clusterSize > 0f && ( f == 0f || i == hist.Length - 1)){
166 list.Add(
new KeyValuePair<int, float>(clusterStart + (i - clusterStart)/2, clusterSize));
174 list.Sort(CompareValue);
192 int upperBound = index;
193 int lowerBound = index;
195 for (
int i=index; i<hist.Length && hist[i] -eps < hist[index]; i++) {
199 for (
int i=index; i>=0 && hist[i] -eps < hist[index] ; i--) {
203 return new int[]{lowerBound, upperBound};
215 int CompareKey(KeyValuePair<int, float> a, KeyValuePair<int, float> b)
217 return a.Key.CompareTo(b.Key);
229 int CompareValue(KeyValuePair<int, float> a, KeyValuePair<int, float> b)
231 return a.Value.CompareTo(b.Value);
Histogram(Texture2D binaryImage, Rect a1)
A histogram of a binary image.
List< KeyValuePair< int, float > > findCluster(float[] hist)
Finds all clusters in the given histogram.
List< KeyValuePair< int, float > > findMin(float[] hist)
Finds all local minima in the given histogram.
List< KeyValuePair< int, float > > findMax(float[] hist)
Finds all local maxima in the given histogram.
void draw()
Draws the histogram.
int[] findSimilarArea(int index, float eps, float[] hist)
Finds all surrounding Values, which are not larger than the value with the given index by eps in the ...