public void CompareQuantizedImages()
        {
            ReportStart();
            _oq = new OctreeQuantizer( 255, 8 );
            for( int colourCount = 1; colourCount < 500; colourCount += 50 )
            {
                Collection<Color> distinctColours;

                Bitmap original = MakeBitmap( new Size( 50, 50 ), colourCount );
                distinctColours = ImageTools.GetDistinctColours( original );
                // Make sure the bitmap we've created has the number of colours we want
                Assert.AreEqual( colourCount, distinctColours.Count );

                Bitmap quantized = _oq.Quantize( original );
                BitmapAssert.AreEqual( original, quantized, 60, // TODO: this is a rather large tolerance
                                       colourCount + " colours" );

                distinctColours = ImageTools.GetDistinctColours( quantized );
                int expectedColours = colourCount > 256 ? 256 : colourCount;
                // FIXME: 65-colour image is quantized down to 64 colours
                // TODO: Check for exact number of colours once Octree quantizer stops reducing colour depth too much
            //				Assert.AreEqual( expectedColours, distinctColours.Count, colourCount + " colours" );
                Assert.LessOrEqual( distinctColours.Count, expectedColours, colourCount + " colours" );
            }
            ReportEnd();
        }
Пример #2
0
        public PixelAnalysis(Image imageToStudy, QuantizerType quantizerType)
        {
            _imageToStudy  = imageToStudy;
            _colourQuality = 10;
            _quantizerType = quantizerType;
            GetColours(imageToStudy);

            if (_distinctColours.Count > 256)
            {
                switch (quantizerType)
                {
                case QuantizerType.NeuQuant:
                    break;

                case QuantizerType.Octree:
                    _oq = new OctreeQuantizer(255, 8);
                    // TODO: progress counters for Octree
                    break;
                }
            }
        }
 public void MaxColourBitsTooLarge()
 {
     ReportStart();
     try
     {
         _oq = new OctreeQuantizer( 10, 9 );
     }
     catch( ArgumentOutOfRangeException ex )
     {
         string message = "This should be between 1 and 8";
         StringAssert.Contains( message, ex.Message );
         Assert.AreEqual( "maxColourBits", ex.ParamName );
         Assert.AreEqual( 9, ex.ActualValue );
         ReportEnd();
         throw;
     }
 }
 public void MaxColoursTooSmall()
 {
     ReportStart();
     try
     {
         _oq = new OctreeQuantizer( 0, 8 );
     }
     catch( ArgumentOutOfRangeException ex )
     {
         string message = "The number of colours should be between 1 and 255";
         StringAssert.Contains( message, ex.Message );
         Assert.AreEqual( "maxColours", ex.ParamName );
         Assert.AreEqual( 0, ex.ActualValue );
         ReportEnd();
         throw;
     }
 }
Пример #5
0
		public PixelAnalysis( Image imageToStudy, QuantizerType quantizerType )
		{
			_imageToStudy = imageToStudy;
			_colourQuality = 10;
			_quantizerType = quantizerType;
			GetColours( imageToStudy );
			
			if( _distinctColours.Count > 256 )
			{
				switch( quantizerType )
				{
					case QuantizerType.NeuQuant:
						break;
						
					case QuantizerType.Octree:
						_oq = new OctreeQuantizer( 255, 8 );
						// TODO: progress counters for Octree
						break;
				}
			}
		}