protected override void OnRenderPixel(Image3D image, DisplayImage display, int x, int y) { if (MarkerX == x || MarkerY == y) { display.SetPixel(x, y, Colors.Orange); } }
/// <summary> /// Process an 3D Image with this element /// </summary> /// <param name="image">Input image</param> /// <returns>Output image</returns> public Image3D Process(Image3D image) { using (var progress = Log.P(ToString())) { try { if (PreProcessing !=null) { PreProcessing(this, new ProcessEventArgs(image)); } return OnProcess(image, progress); } catch (ThreadAbortException) { progress.Abort(); throw; } catch (LogException e) { progress.Abort(); Log.E(e.Message); throw; } } }
protected override Image3D GetOutputImage(Image3D imageIn) { var imageOut = new Image3D(imageIn.LengthY, imageIn.LengthZ, imageIn.LengthX); imageOut.Minimum = imageIn.Minimum; imageOut.Maximum = imageIn.Maximum; return imageOut; }
protected override Image3D OnProcess(Image3D image, Progress progress) { if (cache == null) { if (!CombineFilesToSlices) { using (var reader = new DicomReader(Path)) { cache = reader.ReadImage3D(progress); cache.Minimum = reader.MinValue; cache.Maximum = reader.MaxValue; } } else { using (var reader = new FileToSliceDicomReader(Path)) { cache = reader.ReadImage3D(progress); cache.Minimum = reader.MinValue; cache.Maximum = reader.MaxValue; } } Log.I("Image loaded. min: " + cache.Minimum + "; max: " + cache.Maximum); } return cache; }
protected override void OnProcess2D(Image3D imageIn, Image3D imageOut, int x, int y) { for (int z = 0; z < imageIn.LengthZ; z++) { OnProcess3D(imageIn, imageOut, x, y, z); } }
protected override Image3D OnProcess(Image3D image, Progress progress) { OnValidate(image); Size size = OnDetermineDisplaySize(image); int w = (int)Math.Round(size.Width); int h = (int)Math.Round(size.Height); displayImage = Display.GetDisplay(w, h); var result = base.OnProcess(image, progress); return result; }
protected override Image3D OnProcess(Image3D image, Progress progress) { if (Activated) { return base.OnProcess(image, progress); } else { progress.Done(); return image; } }
protected override Image3D OnProcess(Image3D image, Progress progress) { Image3D imageOut = GetOutputImage(image); int delta = image.LengthY / threads.Length; LineRange firstRange = null; for (int i = 0; i < threads.Length; i++) { int min = delta * i; int max = (i == threads.Length - 1 ? image.LengthY : (delta * (i + 1))); var range = new LineRange(image, imageOut, progress, min, max); if (i == 0) { // run first range in this thread // so save the range for later firstRange = range; } else { threads[i] = new Thread(new ParameterizedThreadStart(ProcessLines)); threads[i].Start(range); } } // allow other threads to start Thread.Sleep(0); // run first range ProcessLines(firstRange); // join all other threads // Attention: start at 1, beacause 0 is null because it was processed in this Thread for (int i = 1; i < threads.Length; i++) { while (threads[i].ThreadState == ThreadState.Unstarted) { Thread.Sleep(0); } threads[i].Join(); } return imageOut; }
public Image3D ReadImage3D(Progress progress) { this.progress = progress; var directory = new DirectoryInfo(path); var files = directory.GetFiles(); // TODO: remove (allow max 900 slices) if (files.Length > 900) { Array.Resize<FileInfo>(ref files, 900); } // --- Image3D slice0; using (var reader0 = new DicomReader(files[0].FullName)) { slice0 = reader0.ReadImage3D(new Progress()); } this.image = new Image3D(files.Length, slice0.LengthY, slice0.LengthX); this.image.CloneSlice(slice0, 0, 0); MinValue = Math.Min(MinValue, slice0.Minimum); MaxValue = Math.Max(MaxValue, slice0.Maximum); slice0 = null; slicesDone++; //ThreadPool.SetMaxThreads(8, 8); for (int z = 1; z < files.Length; z++) { ReadSlice(new SliceInfo(files[z], z)); //ThreadPool.QueueUserWorkItem(new WaitCallback(ReadSlice), ); } while (slicesDone != image.LengthZ) { Thread.Sleep(50); } progress.Done(); path = null; return image; }
public void UpdateImage(Image3D image) { Histogram histogram = new Histogram(Builder.MinValue, Builder.MaxValue, displayImage.Width); histogram.FromImage(image); TransferFunction1D tf = CreateTransferFunction(); histogram.Render(displayImage, tf); Dispatcher.Invoke( () => { displayImage.Update(); imageTfBackground.Width = canvasTf.ActualWidth; imageTfBackground.Height = canvasTf.ActualHeight; //UpdateAll(); } ); }
public static string InfoString(Image3D image) { if (image == null) { return "null"; } else { return image.LengthX + "x" + image.LengthY + "x" + image.LengthZ; } }
protected override void OnProcess2D(Image3D imageIn, Image3D imageOut, int x, int y) { OnRenderPixel(imageIn, displayImage, x, y); }
protected override void OnProcess3D(Image3D imageIn, Image3D imageOut, int x, int y, int z) { imageOut[x, z, y] = imageIn[x, y, z]; }
public void Dispose() { disposed = true; image = null; progress = null; }
protected virtual Image3D GetOutputImage(Image3D imageIn) { return imageIn.EmptyCopy(); }
public LineRange(Image3D imageIn, Image3D imageOut, Progress progress, int min, int max) { this.ImageIn = imageIn; this.ImageOut = imageOut; this.Progress = progress; this.Min = min; this.Max = max; }
public ProcessEventArgs(Image3D image) { this.Image = image; }
protected override Image3D GetOutputImage(Image3D imageIn) { return imageIn; // do not create new output image, use input instead, because it shouldn't be modified in a renderer }
public Image3D EmptyCopy() { var result = new Image3D(LengthZ, LengthY, LengthX); result.Minimum = Minimum; result.Maximum = Maximum; return result; }
protected virtual Size OnDetermineDisplaySize(Image3D image) { return new Size(image.LengthX, image.LengthY); }
/// <summary> /// Is called for every voxel of the input image /// </summary> /// <param name="imageIn">input image</param> /// <param name="imageOut">output image</param> /// <param name="x">x</param> /// <param name="y">y</param> /// <param name="z">z</param> protected abstract void OnProcess3D(Image3D imageIn, Image3D imageOut, int x, int y, int z);
/// <summary> /// Must be implemented to process the image /// </summary> /// <param name="image">Input image</param> /// <param name="progress">Progress of the process</param> /// <returns>Output image</returns> protected abstract Image3D OnProcess(Image3D image, Progress progress);
protected abstract void OnRenderPixel(Image3D image, DisplayImage display, int x, int y);
protected virtual void OnValidate(Image3D image) { }
public void CloneSlice(Image3D source, int sourceSlice, int destinationSlice) { if (source.LengthX != LengthX || source.LengthY != LengthY) { throw new ArgumentException("Slice dimensions must match!"); } else { this.data[destinationSlice] = source.data[sourceSlice]; } }