Example #1
0
 public static Image1ub ToUnsignedByte( this Image1f im )
 {
     var output = new Image1ub( im.Size );
     for( int k = 0; k < im.NumPixels; ++k )
     {
         output[ k ] = im[ k ].ToUnsignedByte();
     }
     return output;
 }
Example #2
0
 public static void SavePNG( this BitArray arr, Rect2i rect, Vector2i imageSize, string filename )
 {
     Image1ub im = new Image1ub( imageSize );
     
     int i = 0;
     int x0 = rect.Origin.x;
     int y0 = rect.Origin.y;
     for( int y = 0; y < rect.Height; ++y )
     {
         for( int x = 0; x < rect.Width; ++x )
         {
             if( arr[ i ] )
             {
                 im.SetPixelFlipped( x0 + x, y0 + y, 255 );
             }
             ++i;
         }
     }
     im.SavePNG( filename );
 }
Example #3
0
        public static void Apply( Image1f input, Image1ub output )
        {
            if( input.Size != output.Size )
            {
                throw new ArgumentException( "input and output must be of the same size" );
            }

            float min;
            float max;
            input.Pixels.MinMax( f => f, out min, out max );
            float reciprocalRange = 1.0f / ( max - min );

            for( int k = 0; k < input.NumPixels; ++k )
            {
                float vIn = input[ k ];
                float vOut = ( vIn - min ) * reciprocalRange;

                output[ k ] = FormatConversion.ToUnsignedByte( vOut );
            }
        }