@@ -35,6 +35,7 @@ await files.WithRepeatAsync(async (pngFile, token) =>
3535 List < List < double > > data = new List < List < double > > ( ) ;
3636 int count = 0 ;
3737 int totalCount = 0 ;
38+ double [ , ] values = new double [ 512 , 512 ] ;
3839 for ( int i = 0 ; i < 512 ; ++ i )
3940 {
4041 var subvect = new List < double > ( ) ;
@@ -45,6 +46,7 @@ await files.WithRepeatAsync(async (pngFile, token) =>
4546 {
4647 count ++ ;
4748 }
49+ values [ i , j ] = value ;
4850 subvect . Add ( value ) ;
4951 totalCount ++ ;
5052 }
@@ -56,20 +58,22 @@ await files.WithRepeatAsync(async (pngFile, token) =>
5658 int uIndex = file . IndexOf ( "_" ) ;
5759 var prefix = file . Substring ( 0 , uIndex ) ;
5860
59- var glyphFile = pngFile . Replace ( "\\ " + prefix , "\\ " + prefix + "_glyph" ) . Replace ( "svg\\ " , "svg-glyph\\ " ) ;
60- Node [ , ] glyphNodes = ImageSerializer . DeserializeImageWithoutAntiAlias ( glyphFile ) ;
61- Matrix rotationTargets = new Matrix ( 15 , 15 ) ;
62- Vector3 [ ] glyphs = new Vector3 [ 225 ] ;
63- int m = 0 ;
64- for ( int k = 0 ; k < 15 ; ++ k )
65- {
66- for ( int l = 0 ; l < 15 ; ++ l )
67- {
68- rotationTargets [ k , l ] = glyphNodes [ k , l ] . IsForeground ? 1d : 0d ;
69- glyphs [ m ] = new Vector3 ( 0f , 0f , ( float ) rotationTargets [ k , l ] ) ;
70- m ++ ;
71- }
72- }
61+ var percentages = CalculatePercentagesAboveThreshold ( values ) ;
62+
63+ //var glyphFile = pngFile.Replace("\\" + prefix, "\\" + prefix + "_glyph").Replace("svg\\", "svg-glyph\\");
64+ //Node[,] glyphNodes = ImageSerializer.DeserializeImageWithoutAntiAlias(glyphFile);
65+ //Matrix rotationTargets = new Matrix(15, 15);
66+ //Vector3[] glyphs = new Vector3[225];
67+ //int m = 0;
68+ //for (int k = 0; k < 15; ++k)
69+ //{
70+ // for (int l = 0; l < 15; ++l)
71+ // {
72+ // rotationTargets[k, l] = glyphNodes[k, l].IsForeground ? 1d : 0d;
73+ // glyphs[m] = new Vector3(0f, 0f, (float)rotationTargets[k, l]);
74+ // m++;
75+ // }
76+ //}
7377
7478 Matrix matrix = new Matrix ( data . Count , data [ 0 ] . Count ) ;
7579 for ( int j = 0 ; j < data . Count ; j ++ )
@@ -82,7 +86,7 @@ await files.WithRepeatAsync(async (pngFile, token) =>
8286
8387 i ++ ;
8488
85- var res = net . Forward ( matrix , rotationTargets , perc > 35d ? 3 * Math . PI / 4d : Math . PI / 4d ) ;
89+ var res = net . Forward ( matrix , percentages ) ;
8690 var gradient = res . Item1 ;
8791 var output = res . Item2 ;
8892 var loss = res . Item3 ;
@@ -131,5 +135,37 @@ await files.WithRepeatAsync(async (pngFile, token) =>
131135 CudaBlas . Instance . Dispose ( ) ;
132136 }
133137 }
138+
139+ private double [ , ] CalculatePercentagesAboveThreshold ( double [ , ] input , double threshold = 0.5 )
140+ {
141+ int inputWidth = input . GetLength ( 0 ) ; // 512
142+ int inputHeight = input . GetLength ( 1 ) ; // 512
143+ int sectionSize = inputWidth / 8 ; // Assuming the input is always 512x512 and output grid is 8x8
144+
145+ double [ , ] percentages = new double [ 8 , 8 ] ;
146+
147+ for ( int sectionX = 0 ; sectionX < 8 ; sectionX ++ )
148+ {
149+ for ( int sectionY = 0 ; sectionY < 8 ; sectionY ++ )
150+ {
151+ int aboveThresholdCount = 0 ;
152+ for ( int x = sectionX * sectionSize ; x < ( sectionX + 1 ) * sectionSize ; x ++ )
153+ {
154+ for ( int y = sectionY * sectionSize ; y < ( sectionY + 1 ) * sectionSize ; y ++ )
155+ {
156+ if ( input [ x , y ] > threshold )
157+ {
158+ aboveThresholdCount ++ ;
159+ }
160+ }
161+ }
162+
163+ double totalValues = sectionSize * sectionSize ;
164+ percentages [ sectionX , sectionY ] = ( double ) aboveThresholdCount / totalValues ;
165+ }
166+ }
167+
168+ return percentages ;
169+ }
134170 }
135171}
0 commit comments