Exemple #1
0
		public void Test12Unsigned()
		{
			GrayscaleColorMap colorMap = new GrayscaleColorMap();
			colorMap.MinInputValue = 0;
			colorMap.MaxInputValue = 4095;
			
			Assert.IsTrue(colorMap.Length == 4096);

			Color color = Color.FromArgb(colorMap.Data[0]);
			Assert.IsTrue(255 == color.A && 0 == color.R && color.R == color.G && color.G == color.B);

			color = Color.FromArgb(colorMap.Data[2047]);
			Assert.IsTrue(127 == color.R && color.R == color.G && color.G == color.B);

			color = Color.FromArgb(colorMap.Data[4095]);
			Assert.IsTrue(255 == color.R && color.R == color.G && color.G == color.B);
		}
Exemple #2
0
        public void Test12Unsigned()
        {
            GrayscaleColorMap colorMap = new GrayscaleColorMap();

            colorMap.MinInputValue = 0;
            colorMap.MaxInputValue = 4095;

            Assert.IsTrue(colorMap.Length == 4096);

            Color color = Color.FromArgb(colorMap.Data[0]);

            Assert.IsTrue(255 == color.A && 0 == color.R && color.R == color.G && color.G == color.B);

            color = Color.FromArgb(colorMap.Data[2047]);
            Assert.IsTrue(127 == color.R && color.R == color.G && color.G == color.B);

            color = Color.FromArgb(colorMap.Data[4095]);
            Assert.IsTrue(255 == color.R && color.R == color.G && color.G == color.B);
        }
Exemple #3
0
		public void Test12Signed()
		{
			GrayscaleColorMap colorMap = new GrayscaleColorMap();
			colorMap.MinInputValue = -2048;
			colorMap.MaxInputValue = 2047;

			Assert.IsTrue(colorMap.Length == 4096);

			Assert.AreEqual(colorMap.Data[0], colorMap[-2048]);
			Color color = Color.FromArgb(colorMap.Data[0]);
			Assert.IsTrue(255 == color.A && 0 == color.R && color.R == color.G && color.G == color.B);

			Assert.AreEqual(colorMap.Data[2048], colorMap[0]);
			color = Color.FromArgb(colorMap.Data[2048]);
			Assert.IsTrue(127 == color.R && color.R == color.G && color.G == color.B);

			Assert.AreEqual(colorMap.Data[4095], colorMap[2047]);
			color = Color.FromArgb(colorMap.Data[4095]);
			Assert.IsTrue(255 == color.R && color.R == color.G && color.G == color.B);
		}
		public void Test12Unsigned()
		{
		    var colorMap = new GrayscaleColorMap {MinInputValue = 0, MaxInputValue = 4095};

		    Assert.IsTrue(colorMap.Length == 4096);

			Color color = Color.FromArgb(colorMap.Data[0]);
		    Assert.AreEqual(255, color.A);
            Assert.AreEqual(0, color.R);
            Assert.IsTrue(color.R == color.G && color.G == color.B);

            color = Color.FromArgb(colorMap.Data[2048]);
            Assert.AreEqual(255, color.A);
            Assert.IsTrue(color.R == 128);
            Assert.IsTrue(color.R == color.G && color.G == color.B);

			color = Color.FromArgb(colorMap.Data[4095]);
            Assert.AreEqual(255, color.A);
            Assert.AreEqual(255, color.R);
            Assert.IsTrue(color.R == color.G && color.G == color.B);
        }
Exemple #5
0
        public void Test12Signed()
        {
            GrayscaleColorMap colorMap = new GrayscaleColorMap();

            colorMap.MinInputValue = -2048;
            colorMap.MaxInputValue = 2047;

            Assert.IsTrue(colorMap.Length == 4096);

            Assert.AreEqual(colorMap.Data[0], colorMap[-2048]);
            Color color = Color.FromArgb(colorMap.Data[0]);

            Assert.IsTrue(255 == color.A && 0 == color.R && color.R == color.G && color.G == color.B);

            Assert.AreEqual(colorMap.Data[2048], colorMap[0]);
            color = Color.FromArgb(colorMap.Data[2048]);
            Assert.IsTrue(127 == color.R && color.R == color.G && color.G == color.B);

            Assert.AreEqual(colorMap.Data[4095], colorMap[2047]);
            color = Color.FromArgb(colorMap.Data[4095]);
            Assert.IsTrue(255 == color.R && color.R == color.G && color.G == color.B);
        }
Exemple #6
0
        public void Test12Unsigned()
        {
            var colorMap = new GrayscaleColorMap {
                MinInputValue = 0, MaxInputValue = 4095
            };

            Assert.IsTrue(colorMap.Length == 4096);

            Color color = Color.FromArgb(colorMap.Data[0]);

            Assert.AreEqual(255, color.A);
            Assert.AreEqual(0, color.R);
            Assert.IsTrue(color.R == color.G && color.G == color.B);

            color = Color.FromArgb(colorMap.Data[2048]);
            Assert.AreEqual(255, color.A);
            Assert.IsTrue(color.R == 128);
            Assert.IsTrue(color.R == color.G && color.G == color.B);

            color = Color.FromArgb(colorMap.Data[4095]);
            Assert.AreEqual(255, color.A);
            Assert.AreEqual(255, color.R);
            Assert.IsTrue(color.R == color.G && color.G == color.B);
        }
        public void Test8Range()
        {
            var colorMap = new GrayscaleColorMap {MinInputValue = 0, MaxInputValue = 255};

            Assert.AreEqual(colorMap.Data.Length, 256);

            //If the input is 0-255 (e.g. presentation LUT output range),
            //then the color map has to be a no-op.
            for (int i = 0; i < colorMap.Data.Length; ++i)
            {
                var value = 0xFF000000 | (i << 16) | (i << 8) | i;
                Assert.AreEqual((uint)value, (uint)colorMap.Data[i]);
            }
        }
        private byte PerformBilinearInterpolationAt(PointF srcPoint00)
        {
            if (srcPoint00.Y < 0)
            {
                srcPoint00.Y = 0;
            }
            if (srcPoint00.X < 0)
            {
                srcPoint00.X = 0;
            }

            if (srcPoint00.X > (_srcWidth - 1.001F))
            {
                srcPoint00.X = (_srcWidth - 1.001F);
            }
            if (srcPoint00.Y > (_srcHeight - 1.001F))
            {
                srcPoint00.Y = (_srcHeight - 1.001F);
            }

            Point srcPointInt00 = new Point((int)srcPoint00.X, (int)srcPoint00.Y);

            float[,] arrayOfValues = new float[2, 2] {
                { 0, 0 }, { 0, 0 }
            };

            if (IsColor())
            {
                //Just test the R value, the calculation is done in exactly the same way
                //for G & B, so if it's OK for the R channel it's OK for them too.

                //Get the 4 neighbour pixels for performing bilinear interpolation.
                arrayOfValues[0, 0] = (float)ColorPixelData().GetPixelAsColor(srcPointInt00.X, srcPointInt00.Y).R;
                arrayOfValues[0, 1] = (float)ColorPixelData().GetPixelAsColor(srcPointInt00.X, srcPointInt00.Y + 1).R;
                arrayOfValues[1, 0] = (float)ColorPixelData().GetPixelAsColor(srcPointInt00.X + 1, srcPointInt00.Y).R;
                arrayOfValues[1, 1] = (float)ColorPixelData().GetPixelAsColor(srcPointInt00.X + 1, srcPointInt00.Y + 1).R;
            }
            else
            {
                if (_image.BitsPerPixel == 16)
                {
                    //Get the 4 neighbour pixels for performing bilinear interpolation.
                    arrayOfValues[0, 0] = (float)GrayscalePixelData().GetPixel(srcPointInt00.X, srcPointInt00.Y);
                    arrayOfValues[0, 1] = (float)GrayscalePixelData().GetPixel(srcPointInt00.X, srcPointInt00.Y + 1);
                    arrayOfValues[1, 0] = (float)GrayscalePixelData().GetPixel(srcPointInt00.X + 1, srcPointInt00.Y);
                    arrayOfValues[1, 1] = (float)GrayscalePixelData().GetPixel(srcPointInt00.X + 1, srcPointInt00.Y + 1);
                }
                else if (_image.BitsPerPixel == 8)
                {
                    //Get the 4 neighbour pixels for performing bilinear interpolation.
                    arrayOfValues[0, 0] = (float)GrayscalePixelData().GetPixel(srcPointInt00.X, srcPointInt00.Y);
                    arrayOfValues[0, 1] = (float)GrayscalePixelData().GetPixel(srcPointInt00.X, srcPointInt00.Y + 1);
                    arrayOfValues[1, 0] = (float)GrayscalePixelData().GetPixel(srcPointInt00.X + 1, srcPointInt00.Y);
                    arrayOfValues[1, 1] = (float)GrayscalePixelData().GetPixel(srcPointInt00.X + 1, srcPointInt00.Y + 1);
                }
            }

            //TraceLine(String.Format("Pt: ({0}, {1})", srcPoint00.X, srcPoint00.Y));
            //TraceLine(String.Format("Values:\n{0}  {1}\n{2}  {3}", arrayOfValues[0, 0], arrayOfValues[1, 0], arrayOfValues[0, 1], arrayOfValues[1, 1]));

            //this actually performs the bilinear interpolation within the source image using 4 neighbour pixels.
            float dx = srcPoint00.X - (float)srcPointInt00.X;
            float dy = srcPoint00.Y - (float)srcPointInt00.Y;

            int dyFixed = (int)(dy * _fixedScale);
            int dxFixed = (int)(dx * _fixedScale);

            int yInterpolated1 = (((int)(arrayOfValues[0, 0])) << _fixedPrecision) + ((dyFixed * ((int)((arrayOfValues[0, 1] - arrayOfValues[0, 0])) << _fixedPrecision)) >> _fixedPrecision);
            int yInterpolated2 = (((int)(arrayOfValues[1, 0])) << _fixedPrecision) + ((dyFixed * ((int)((arrayOfValues[1, 1] - arrayOfValues[1, 0])) << _fixedPrecision)) >> _fixedPrecision);
            int interpolated   = (yInterpolated1 + (((dxFixed) * (yInterpolated2 - yInterpolated1)) >> _fixedPrecision)) >> _fixedPrecision;

            //TraceLine(String.Format("Pt: ({0}, {1})", srcPoint00.X, srcPoint00.Y));
            //TraceLine(String.Format("Values:\n{0}  {1}\n{2}  {3}", arrayOfValues[0, 0], arrayOfValues[1, 0], arrayOfValues[0, 1], arrayOfValues[1, 1]));
            //TraceLine(String.Format("dx, dy = {0}, {1}", dx, dy));
            //TraceLine(String.Format("interpolated = {0}", interpolated));

            if (IsColor())
            {
                return((byte)interpolated);
            }

            //The image's LutComposer is private, so we just replicate it here and recalculate.
            GrayscaleImageGraphic graphic  = (GrayscaleImageGraphic)_image;
            LutComposer           composer = new LutComposer(graphic.BitsStored, graphic.IsSigned);

            composer.ModalityLut = graphic.ModalityLut;
            composer.VoiLut      = graphic.VoiLut;
            var colorMap = new GrayscaleColorMap();

            colorMap.MaxInputValue = composer.MaxOutputValue;
            colorMap.MinInputValue = composer.MinOutputValue;
            return(Color.FromArgb(colorMap[composer[interpolated]]).R);
        }
		private byte PerformBilinearInterpolationAt(PointF srcPoint00)
		{
			if (srcPoint00.Y < 0)
				srcPoint00.Y = 0;
			if (srcPoint00.X < 0)
				srcPoint00.X = 0;

			if (srcPoint00.X > (_srcWidth - 1.001F))
				srcPoint00.X = (_srcWidth - 1.001F);
			if (srcPoint00.Y > (_srcHeight - 1.001F))
				srcPoint00.Y = (_srcHeight - 1.001F);

			Point srcPointInt00 = new Point((int)srcPoint00.X, (int)srcPoint00.Y);

			float[,] arrayOfValues = new float[2, 2] { { 0, 0 }, { 0, 0 } };

			if (IsColor())
			{
				//Just test the R value, the calculation is done in exactly the same way 
				//for G & B, so if it's OK for the R channel it's OK for them too.

				//Get the 4 neighbour pixels for performing bilinear interpolation.
				arrayOfValues[0, 0] = (float)ColorPixelData().GetPixelAsColor(srcPointInt00.X, srcPointInt00.Y).R;
				arrayOfValues[0, 1] = (float)ColorPixelData().GetPixelAsColor(srcPointInt00.X, srcPointInt00.Y + 1).R;
				arrayOfValues[1, 0] = (float)ColorPixelData().GetPixelAsColor(srcPointInt00.X + 1, srcPointInt00.Y).R;
				arrayOfValues[1, 1] = (float)ColorPixelData().GetPixelAsColor(srcPointInt00.X + 1, srcPointInt00.Y + 1).R;
			}
			else
			{
				if (_image.BitsPerPixel == 16)
				{
					//Get the 4 neighbour pixels for performing bilinear interpolation.
					arrayOfValues[0, 0] = (float)GrayscalePixelData().GetPixel(srcPointInt00.X, srcPointInt00.Y);
					arrayOfValues[0, 1] = (float)GrayscalePixelData().GetPixel(srcPointInt00.X, srcPointInt00.Y + 1);
					arrayOfValues[1, 0] = (float)GrayscalePixelData().GetPixel(srcPointInt00.X + 1, srcPointInt00.Y);
					arrayOfValues[1, 1] = (float)GrayscalePixelData().GetPixel(srcPointInt00.X + 1, srcPointInt00.Y + 1);
				}
				else if (_image.BitsPerPixel == 8)
				{
					//Get the 4 neighbour pixels for performing bilinear interpolation.
					arrayOfValues[0, 0] = (float)GrayscalePixelData().GetPixel(srcPointInt00.X, srcPointInt00.Y);
					arrayOfValues[0, 1] = (float)GrayscalePixelData().GetPixel(srcPointInt00.X, srcPointInt00.Y + 1);
					arrayOfValues[1, 0] = (float)GrayscalePixelData().GetPixel(srcPointInt00.X + 1, srcPointInt00.Y);
					arrayOfValues[1, 1] = (float)GrayscalePixelData().GetPixel(srcPointInt00.X + 1, srcPointInt00.Y + 1);
				}
			}

			//TraceLine(String.Format("Pt: ({0}, {1})", srcPoint00.X, srcPoint00.Y));
			//TraceLine(String.Format("Values:\n{0}  {1}\n{2}  {3}", arrayOfValues[0, 0], arrayOfValues[1, 0], arrayOfValues[0, 1], arrayOfValues[1, 1]));

			//this actually performs the bilinear interpolation within the source image using 4 neighbour pixels.
			float dx = srcPoint00.X - (float)srcPointInt00.X;
			float dy = srcPoint00.Y - (float)srcPointInt00.Y;
			
			int dyFixed = (int)(dy * _fixedScale);
			int dxFixed = (int)(dx * _fixedScale);

			int yInterpolated1 = (((int)(arrayOfValues[0, 0])) << _fixedPrecision) + ((dyFixed * ((int)((arrayOfValues[0, 1] - arrayOfValues[0, 0])) << _fixedPrecision)) >> _fixedPrecision);
			int yInterpolated2 = (((int)(arrayOfValues[1, 0])) << _fixedPrecision) + ((dyFixed * ((int)((arrayOfValues[1, 1] - arrayOfValues[1, 0])) << _fixedPrecision)) >> _fixedPrecision);
			int interpolated = (yInterpolated1 + (((dxFixed) * (yInterpolated2 - yInterpolated1)) >> _fixedPrecision)) >> _fixedPrecision;

			//TraceLine(String.Format("Pt: ({0}, {1})", srcPoint00.X, srcPoint00.Y));
			//TraceLine(String.Format("Values:\n{0}  {1}\n{2}  {3}", arrayOfValues[0, 0], arrayOfValues[1, 0], arrayOfValues[0, 1], arrayOfValues[1, 1]));
			//TraceLine(String.Format("dx, dy = {0}, {1}", dx, dy));
			//TraceLine(String.Format("interpolated = {0}", interpolated));

			if (IsColor())
				return (byte)interpolated;

			//The image's LutComposer is private, so we just replicate it here and recalculate.
			GrayscaleImageGraphic graphic = (GrayscaleImageGraphic) _image;
			LutComposer composer = new LutComposer(graphic.BitsStored, graphic.IsSigned);
			composer.ModalityLut = graphic.ModalityLut;
			composer.VoiLut = graphic.VoiLut;
			var colorMap = new GrayscaleColorMap();
			colorMap.MaxInputValue = composer.MaxOutputValue;
			colorMap.MinInputValue = composer.MinOutputValue;
			return Color.FromArgb(colorMap[composer[interpolated]]).R;
		}