コード例 #1
0
ファイル: ItkHelper.cs プロジェクト: nhannd/Xian
 public static void CopyToItkImage(GrayscaleImageGraphic image, itkImageBase itkImage)
 {
     if (image.BitsPerPixel == 16)
     {
         if (image.IsSigned)
         {
             CopyToSigned16(image, itkImage);
         }
         else
         {
             CopyToUnsigned16(image, itkImage);
         }
     }
     else
     {
         if (image.IsSigned)
         {
             CopyToSigned8(image, itkImage);
         }
         else
         {
             CopyToUnsigned8(image, itkImage);
         }
     }
 }
コード例 #2
0
		private void OnCloneComplete()
		{
			_overlayImageGraphic = (GrayscaleImageGraphic) CollectionUtils.SelectFirst(base.Graphics, g => g is GrayscaleImageGraphic);
			if (_overlayImageGraphic != null)
			{
				_voiLutManagerProxy.SetRealVoiLutManager(_overlayImageGraphic.VoiLutManager);
				_colorMapManagerProxy.SetRealColorMapManager(_overlayImageGraphic.ColorMapManager);
			}
		}
コード例 #3
0
		protected override void Dispose(bool disposing)
		{
			if (disposing)
			{
				_overlayImageGraphic = null;
				_voiLutManagerProxy = null;
				_colorMapManagerProxy = null;

				if (_overlayFrameDataReference != null)
				{
					_overlayFrameDataReference.FusionOverlayFrameData.Unloaded -= HandleOverlayFrameDataUnloaded;
					_overlayFrameDataReference.Dispose();
					_overlayFrameDataReference = null;
				}
			}

			base.Dispose(disposing);
		}
コード例 #4
0
ファイル: TestPattern.cs プロジェクト: m-berkani/ClearCanvas
		/// <summary>
		/// Creates a test pattern of <paramref name="size"/> consisting of a NW to SE black to white gradient.
		/// </summary>
		public static GrayscaleImageGraphic CreateGraydient(Size size)
		{
			int width = size.Width;
			int height = size.Height;

			GrayscaleImageGraphic imageGraphic = new GrayscaleImageGraphic(height, width);

			int range = (1 << imageGraphic.BitsStored) - 1;
			int offset = imageGraphic.IsSigned ? -(1 << (imageGraphic.BitsStored - 1)) : 0;

			for (int x = 0; x < width; x++)
			{
				for (int y = 0; y < height; y++)
				{
					int v = (int) (1f*(x+y)/(width+height)*range + offset);
					imageGraphic.PixelData.SetPixel(x, y, v);
				}
			}
			return imageGraphic;
		}
コード例 #5
0
ファイル: ItkHelper.cs プロジェクト: nhannd/Xian
		/// <summary>
		/// Create a managed ITK image from a given ClearCanvas image.
		/// </summary>
		/// <param name="image">The given grayscale image.</param>
        public static itkImageBase CreateItkImage(GrayscaleImageGraphic image)
		{
            itkPixelType pixelType;
            if (image.BitsPerPixel == 16)
            {
                if (image.IsSigned)
                {
                    pixelType = itkPixelType.SS;
                }
                else
                {
                    pixelType = itkPixelType.SS;// itkPixelType.US; there is no itkImage_US<dim>
                }
            }
            else //if (image.BitsPerPixel == 8)
            {
                if (image.IsSigned)
                {
                    pixelType = itkPixelType.UC;// itkPixelType.SC; threre is no itkImage_UC<dim>
                }
                else
                {
                    pixelType = itkPixelType.UC;
                }
            }
            itkImage itkImage = itkImage.New(pixelType, 2);
            // Create some image information
            itkSize size = new itkSize(image.Columns, image.Rows);
            itkSpacing spacing = new itkSpacing(1.0, 1.0);
            itkIndex index = new itkIndex(0, 0);
            itkPoint origin = new itkPoint(0.0, 0.0);
            itkImageRegion region = new itkImageRegion(size, index);
            // Set the information
            // Note: we must call SetRegions() *before* calling Allocate().
            itkImage.SetRegions(region);
            itkImage.Allocate();
            itkImage.Spacing = spacing;
            itkImage.Origin = origin;
            //itkImage.BufferedRegion;
            return itkImage;
		}
コード例 #6
0
ファイル: ImageRenderer.cs プロジェクト: nhannd/Xian
		private static void RenderGrayscale(
			GrayscaleImageGraphic image, 
			RectangleF srcViewableRectangle, 
			Rectangle dstViewableRectangle,
			IntPtr pDstPixelData,
			int dstWidth,
			int dstBytesPerPixel)
		{
			fixed (byte* pSrcPixelData = image.PixelData.Raw)
			{
				if (image.InterpolationMode == InterpolationMode.Bilinear)
				{
					int[] finalLutBuffer = ConstructFinalLut(image.OutputLut, image.ColorMap, image.Invert);

					fixed (int* pFinalLutData = finalLutBuffer)
					{
						ImageInterpolatorBilinear.LutData lutData;
						lutData.Data = pFinalLutData;
						lutData.FirstMappedPixelData = image.OutputLut.MinInputValue;
						lutData.Length = finalLutBuffer.Length;

						ImageInterpolatorBilinear.Interpolate(
							srcViewableRectangle,
							pSrcPixelData,
							image.Columns,
							image.Rows,
							image.BytesPerPixel,
							image.BitsStored,
							dstViewableRectangle,
							(byte*) pDstPixelData,
							dstWidth,
							dstBytesPerPixel,
							IsRotated(image),
							&lutData, //ok because it's a local variable in an unsafe method, therefore it's already fixed.
							false,
							false,
							image.IsSigned);
					}
				}
			}
		}
コード例 #7
0
ファイル: TestPattern.cs プロジェクト: nhannd/Xian
		/// <summary>
		/// Creates a test pattern of <paramref name="size"/> consisting of a black and white checkboard.
		/// </summary>
		public static GrayscaleImageGraphic CreateCheckerboard(Size size)
		{
			int width = size.Width;
			int height = size.Height;

			GrayscaleImageGraphic imageGraphic = new GrayscaleImageGraphic(height, width);

			int minValue = imageGraphic.IsSigned ? -(1 << (imageGraphic.BitsStored - 1)) : 0;
			int maxValue = (1 << imageGraphic.BitsStored) + minValue - 1;

			for (int x = 0; x < width; x++)
			{
				for (int y = 0; y < height; y++)
				{
					int file = (int) (8f*x/width);
					int rank = (int) (8f*y/height);
					int v = (file%2 == 0) ^ (rank%2 == 0) ? minValue : maxValue;
					imageGraphic.PixelData.SetPixel(x, y, v);
				}
			}

			return imageGraphic;
		}
コード例 #8
0
		private void HandleOverlayFrameDataUnloaded(object sender, EventArgs e)
		{
			OverlayImageGraphic = null;
		}
コード例 #9
0
		public override void OnDrawing()
		{
			// if the remove graphic flag was set, we need to remove the old graphic because it is no longer valid, and create a new one
			if (_removeGraphic)
			{
				OverlayImageGraphic = null;
				_removeGraphic = false;
			}

			_overlayFrameDataReference.FusionOverlayFrameData.Lock();
			try
			{
				if (_overlayImageGraphic == null)
				{
					if (this.ParentPresentationImage == null || !this.ParentPresentationImage.Visible)
					{
						// we're drawing to an offscreen buffer, so force the frame data to load synchronously now (progress bars must be visible to be useful)
						_overlayFrameDataReference.FusionOverlayFrameData.Load();
					}

					var progressGraphic = (ProgressGraphic) CollectionUtils.SelectFirst(this.Graphics, g => g is ProgressGraphic);

					//TODO (CR Sept 2010): as mentioned in the progress graphic code, this API is unclear
					//and doesn't guarantee that the image won't be unloaded before CreateImageGraphic is called.
					float progress;
					string message;
					if (_overlayFrameDataReference.FusionOverlayFrameData.BeginLoad(out progress, out message))
					{
						OverlayImageGraphic = _overlayFrameDataReference.FusionOverlayFrameData.CreateImageGraphic();

						if (progressGraphic != null)
						{
							this.Graphics.Remove(progressGraphic);
							progressGraphic.Dispose();
						}
					}
					else if (progressGraphic == null)
					{
						this.Graphics.Add(new ProgressGraphic(_overlayFrameDataReference.FusionOverlayFrameData, true, ProgressBarGraphicStyle.Continuous));
					}
				}
				base.OnDrawing();
			}
			finally
			{
				_overlayFrameDataReference.FusionOverlayFrameData.Unlock();
			}
		}
コード例 #10
0
		private static GrayscaleImageGraphic CreateOverlayImageGraphic(OverlayPlane overlayPlaneIod, byte[] overlayData)
		{
			Point origin = (overlayPlaneIod.OverlayOrigin ?? new Point(1, 1)) - new Size(1, 1);
			int rows = overlayPlaneIod.OverlayRows;
			int cols = overlayPlaneIod.OverlayColumns;

			if (overlayData == null || overlayData.Length == 0)
				return null;

			GrayscaleImageGraphic imageGraphic = new GrayscaleImageGraphic(
				rows, cols, // the reported overlay dimensions
				8, // bits allocated is always 8
				8, // overlays always have bit depth of 1, but we upconverted the data
				7, // the high bit is now 7 after upconverting
				false, false, // overlays aren't signed and don't get inverted
				1, 0, // overlays have no rescale
				overlayData); // the upconverted overlay data

			imageGraphic.SpatialTransform.TranslationX = origin.X;
			imageGraphic.SpatialTransform.TranslationY = origin.Y;

			return imageGraphic;
		}
コード例 #11
0
		private void OnCloneComplete()
		{
			_colorBar = (GrayscaleImageGraphic) CollectionUtils.SelectFirst(base.Graphics, g => g is GrayscaleImageGraphic);
		}
コード例 #12
0
		/// <summary>
		/// Constructs a new user-created <see cref="OverlayPlaneGraphic"/> with the specified dimensions.
		/// </summary>
		/// <param name="rows">The number of rows in the overlay.</param>
		/// <param name="columns">The number of columns in the overlay.</param>
		protected OverlayPlaneGraphic(int rows, int columns)
		{
			Platform.CheckPositive(rows, "rows");
			Platform.CheckPositive(columns, "columns");

			_index = -1;
			_frameIndex = 0;
			_label = string.Empty;
			_description = string.Empty;
			_type = OverlayType.G;
			_subtype = null;
			_source = OverlayPlaneSource.User;
			_overlayGraphic = new GrayscaleImageGraphic(
				rows, columns, // the reported overlay dimensions
				8, // bits allocated is always 8
				8, // overlays always have bit depth of 1, but we upconverted the data
				7, // the high bit is now 7 after upconverting
				false, false, // overlays aren't signed and don't get inverted
				1, 0, // overlays have no rescale
				MemoryManager.Allocate<byte>(rows*columns)); // new empty pixel buffer

			this.Color = System.Drawing.Color.PeachPuff;
			base.Graphics.Add(_overlayGraphic);
		}
コード例 #13
0
		/// <summary>
		/// Cloning constructor.
		/// </summary>
		protected GrayscaleImageGraphic(GrayscaleImageGraphic source, ICloningContext context)
			: base(source, context)
		{
			context.CloneFields(source, this);

			if (source.LutComposer.ModalityLut != null) //modality lut is constant; no need to clone.
				this.InitializeNecessaryLuts(Luts.Modality);

			if (source.LutComposer.NormalizationLut != null)
				LutComposer.NormalizationLut = source.NormalizationLut.Clone();

			if (source.LutComposer.VoiLut != null) //clone the voi lut.
				(this as IVoiLutInstaller).InstallVoiLut(CloneVoiLut(source.VoiLut));

			if (source.LutComposer.PresentationLut != null) //not really necessary, but consistent.
				LutComposer.PresentationLut = source.PresentationLut.Clone();

			//color map has already been cloned.
		}
コード例 #14
0
		public override void OnDrawing()
		{
			//TODO (CR Sept 2010): we already uncovered a bug related to this class and the MemoryManager.
			//We need to figure out a way to synchronize the functionality in this class along with the
			//volume/frame data being loaded and unloaded.

			if (_overlayImageGraphic == null)
			{
				_overlayFrameDataReference.FusionOverlayFrameData.Lock();
				try
				{
					if (this.ParentPresentationImage == null || !this.ParentPresentationImage.Visible)
					{
						// we're drawing to an offscreen buffer, so force the frame data to load synchronously now (progress bars must be visible to be useful)
						_overlayFrameDataReference.FusionOverlayFrameData.Load();
					}

					var progressGraphic = (ProgressGraphic) CollectionUtils.SelectFirst(this.Graphics, g => g is ProgressGraphic);

					//TODO (CR Sept 2010): as mentioned in the progress graphic code, this API is unclear
					//and doesn't guarantee that the image won't be unloaded before CreateImageGraphic is called.
					float progress;
					string message;
					if (_overlayFrameDataReference.FusionOverlayFrameData.BeginLoad(out progress, out message))
					{
						OverlayImageGraphic = _overlayFrameDataReference.FusionOverlayFrameData.CreateImageGraphic();

						if (progressGraphic != null)
						{
							this.Graphics.Remove(progressGraphic);
							progressGraphic.Dispose();
						}
					}
					else if (progressGraphic == null)
					{
						this.Graphics.Add(new ProgressGraphic(_overlayFrameDataReference.FusionOverlayFrameData, true, ProgressBarGraphicStyle.Continuous));
					}
				}
				finally
				{
					_overlayFrameDataReference.FusionOverlayFrameData.Unlock();
				}
			}
			base.OnDrawing();
		}
コード例 #15
0
ファイル: MprProbeTool.cs プロジェクト: nhannd/Xian
		private void GetVoiLutValue(
			GrayscaleImageGraphic grayscaleImage,
			double modalityLutValue,
			ref int voiLutValue,
			ref string voiLutString)
		{
			if (grayscaleImage.VoiLut != null)
			{
				voiLutValue = grayscaleImage.VoiLut[modalityLutValue];
				voiLutString = String.Format(SR.FormatVoiLutValue, voiLutValue);
			}
		}
コード例 #16
0
ファイル: MprProbeTool.cs プロジェクト: nhannd/Xian
		private void GetModalityLutValue(
			GrayscaleImageGraphic grayscaleImage,
			int pixelValue,
			ref double modalityLutValue,
			ref string modalityLutString)
		{
			if (grayscaleImage.ModalityLut != null)
			{
				modalityLutValue = grayscaleImage.ModalityLut[pixelValue];
				modalityLutString = String.Format(SR.FormatModalityLutValue, modalityLutValue);

				if (_selectedImageSop != null)
				{
					if (String.Compare(_selectedImageSop.Modality, "CT", true) == 0)
						modalityLutString += String.Format(" ({0})", SR.LabelHounsfieldUnitsAbbreviation);
				}
			}
		}
コード例 #17
0
ファイル: MprProbeTool.cs プロジェクト: nhannd/Xian
		private void GetPixelValue(
			GrayscaleImageGraphic grayscaleImage,
			Point sourcePointRounded,
			ref int pixelValue,
			ref string pixelValueString)
		{
			pixelValue = grayscaleImage.PixelData.GetPixel(sourcePointRounded.X, sourcePointRounded.Y);
			pixelValueString = String.Format(SR.FormatPixelValue, pixelValue);
		}
コード例 #18
0
		/// <summary>
		/// Releases all resources used by this <see cref="ColorBarGraphic"/>.
		/// </summary>
		protected override void Dispose(bool disposing)
		{
			if (disposing)
			{
				_colorBar = null;

				if (_gradientPixelData != null)
				{
					_gradientPixelData.Dispose();
					_gradientPixelData = null;
				}
			}

			base.Dispose(disposing);
		}
コード例 #19
0
		//TODO (CR Sept 2010): Remove if unused.
		public GrayscaleImageGraphic CreateStaticOverlayImageGraphic(bool forceLoad)
		{
			_overlayFrameDataReference.FusionOverlayFrameData.Lock();
			try
			{
				if (!_overlayFrameDataReference.FusionOverlayFrameData.IsLoaded)
				{
					if (!forceLoad)
						return null;

					_overlayFrameDataReference.FusionOverlayFrameData.Load();
				}

				if (OverlayImageGraphic == null)
					OverlayImageGraphic = _overlayFrameDataReference.FusionOverlayFrameData.CreateImageGraphic();

				var staticClone = new GrayscaleImageGraphic(
					OverlayImageGraphic.Rows, OverlayImageGraphic.Columns,
					OverlayImageGraphic.BitsPerPixel, OverlayImageGraphic.BitsStored, OverlayImageGraphic.HighBit,
					OverlayImageGraphic.IsSigned, OverlayImageGraphic.Invert,
					OverlayImageGraphic.RescaleSlope, OverlayImageGraphic.RescaleIntercept,
					OverlayImageGraphic.PixelData.Raw);
				staticClone.VoiLutManager.SetMemento(OverlayImageGraphic.VoiLutManager.CreateMemento());
				staticClone.ColorMapManager.SetMemento(OverlayImageGraphic.ColorMapManager.CreateMemento());
				staticClone.SpatialTransform.SetMemento(OverlayImageGraphic.SpatialTransform.CreateMemento());
				return staticClone;
			}
			finally
			{
				_overlayFrameDataReference.FusionOverlayFrameData.Unlock();
			}
		}
コード例 #20
0
		/// <summary>
		/// Called to unload the colour bar graphic and any associated resources.
		/// </summary>
		protected virtual void UnloadColorBar()
		{
			if (_colorBar != null)
			{
				base.Graphics.Remove(_colorBar);
				_colorBar.Dispose();
				_colorBar = null;
			}

			if (_gradientPixelData != null)
			{
				_gradientPixelData.Dispose();
				_gradientPixelData = null;
			}
		}
コード例 #21
0
		public CadOverlayGraphic(GrayscaleImageGraphic image) 
			: base(image.Rows, image.Columns)
		{
			_image = image;		
		}
コード例 #22
0
		private void OnCloneComplete()
		{
			_overlayGraphic = CollectionUtils.SelectFirst(base.Graphics,
			                                              delegate(IGraphic graphic) { return graphic is GrayscaleImageGraphic; }) as GrayscaleImageGraphic;
		}
コード例 #23
0
				private static GrayscaleImageGraphic CreateTestPattern(byte[] data)
				{
					GrayscaleImageGraphic imageGraphic = new GrayscaleImageGraphic(_height, _width);
					for (int x = 0; x < _width; x++)
					{
						for (int y = 0; y < _height; y++)
						{
							imageGraphic.PixelData.SetPixel(x, y, data[x*_width + y]);
						}
					}
					return imageGraphic;
				}
コード例 #24
0
		/// <summary>
		/// Constructs an <see cref="OverlayPlaneGraphic"/> for a single or multi-frame overlay plane using a pre-processed overlay pixel data buffer.
		/// </summary>
		/// <remarks>
		/// <para>
		/// The <paramref name="overlayPixelData"/> parameter allows for the specification of an alternate source of overlay pixel data, such
		/// as the unpacked contents of <see cref="DicomTags.OverlayData"/> or the extracted, inflated overlay pixels of <see cref="DicomTags.PixelData"/>.
		/// Although the format should be 8-bits per pixel, every pixel should either be 0 or 255. This will allow pixel interpolation algorithms
		/// sufficient range to produce a pleasant image. (If the data was either 0 or 1, regardless of the bit-depth, most interpolation algorithms
		/// will interpolate 0s for everything in between!)
		/// </para>
		/// </remarks>
		/// <param name="overlayPlaneIod">The IOD object containing properties of the overlay plane.</param>
		/// <param name="overlayPixelData">The overlay pixel data in 8-bits per pixel format, with each pixel being either 0 or 255.</param>
		/// <param name="frameIndex">The overlay frame index (0-based). Single-frame overlays should specify 0.</param>
		/// <param name="source">A value identifying the source of the overlay plane.</param>
		/// <exception cref="ArgumentNullException">Thrown if <paramref name="overlayPixelData"/> is NULL or 0-length.</exception>
		public OverlayPlaneGraphic(OverlayPlane overlayPlaneIod, byte[] overlayPixelData, int frameIndex, OverlayPlaneSource source)
		{
			Platform.CheckNonNegative(frameIndex, "frameIndex");
			_frameIndex = frameIndex;
			_index = overlayPlaneIod.Index;
			_label = overlayPlaneIod.OverlayLabel;
			_description = overlayPlaneIod.OverlayDescription;
			_type = overlayPlaneIod.OverlayType;
			_subtype = (OverlayPlaneSubtype) overlayPlaneIod.OverlaySubtype;
			_source = source;

			GrayscaleImageGraphic overlayImageGraphic = CreateOverlayImageGraphic(overlayPlaneIod, overlayPixelData);
			if (overlayImageGraphic != null)
			{
				_overlayGraphic = overlayImageGraphic;
				this.Color = System.Drawing.Color.PeachPuff;
				base.Graphics.Add(overlayImageGraphic);
			}

			if (string.IsNullOrEmpty(overlayPlaneIod.OverlayLabel))
			{
				if (overlayPlaneIod.IsMultiFrame)
					base.Name = string.Format(SR.FormatDefaultMultiFrameOverlayGraphicName, _source, _index, frameIndex);
				else
					base.Name = string.Format(SR.FormatDefaultSingleFrameOverlayGraphicName, _source, _index, frameIndex);
			}
			else
			{
				base.Name = overlayPlaneIod.OverlayLabel;
			}
		}
コード例 #25
0
        public SegFrameImageGraphic(int rows, int columns, float xLocation, float yLocation, Color color, int frameIndex,
                                    int index, string label, string description, byte[] pixelData,
                                    SegmentationDocumentReference segmentationDocumentReference)
        {
            Platform.CheckPositive(rows, "rows");
            Platform.CheckPositive(columns, "columns");
            Platform.CheckNonNegative(frameIndex, "frameIndex");

            _index = index;
            _frameIndex = frameIndex;
            Label = string.IsNullOrEmpty(label) ? string.Empty : label;
            Description = string.IsNullOrEmpty(description) ? string.Empty : description;
            SegmentationDocumentReference = segmentationDocumentReference;

            // new empty pixel buffer
            if (pixelData == null)
                pixelData = MemoryManager.Allocate<byte>(rows*columns);

            _overlayGraphic = new GrayscaleImageGraphic(
                rows, columns, // the reported overlay dimensions
                8, // bits allocated is always 8
                8, // overlays always have bit depth of 1, but we upconverted the data
                7, // the high bit is now 7 after upconverting
                false, false, // overlays aren't signed and don't get inverted
                1, 0, // overlays have no rescale
                pixelData); // the upconverted overlay data

            _overlayGraphic.SpatialTransform.TranslationX = xLocation;
            _overlayGraphic.SpatialTransform.TranslationY = yLocation;

            Color = color;
            Graphics.Add(_overlayGraphic);
        }