public void EdgesClickHandler(object sender, EventArgs e) { if (image != null) { Bitmap imx = new Bitmap(path); Edges gb = new Edges(); imx = gb.Apply(imx); if (mov != null) { this.WorkItem.Workspaces[WorkspaceNames.TabWorkspace].Close(mov); } mov = this.WorkItem.SmartParts.AddNew <ImageAView>(); mov.panAndZoomPictureBox1.Image = imx; SmartPartInfo spi = new SmartPartInfo("Edges", "MyOwnDescription"); this.WorkItem.Workspaces[WorkspaceNames.TabWorkspace].Show(mov, spi); } }
protected void ImageButton1_Click(object sender, ImageClickEventArgs e) { if (FileUpload1.HasFile) { string filename = "C:\\Users\\darwesh\\Documents\\Visual Studio 2010\\WebSites\\WebSite1\\Images\\" + FileUpload1.FileName; string filedir = "C:\\Users\\darwesh\\Documents\\Visual Studio 2010\\WebSites\\WebSite1\\"; FileUpload1.SaveAs("C:\\Users\\darwesh\\Documents\\Visual Studio 2010\\WebSites\\WebSite1\\Images\\" + FileUpload1.FileName); pixels16 = new List <ushort>(); Imagemri im = new Imagemri(); DicomDecoder dd = new DicomDecoder(); dd.DicomFileName = filename; imageWidth = dd.width; imageHeight = dd.height; bitDepth = dd.bitsAllocated; winCentre = dd.windowCentre; winWidth = dd.windowWidth; bool result = dd.dicomFileReadSuccess; if (result == true) { im.NewImage = true; if (bitDepth == 16) { pixels16.Clear(); dd.GetPixels16(ref pixels16); byte[] buffer = new byte[pixels16.Count * 2]; byte[] temp; ByteConverter d = new ByteConverter(); int j = 0; for (int i = 0; i < pixels16.Count; i++) { temp = System.BitConverter.GetBytes(pixels16[i]); buffer[j++] = temp[0]; buffer[j++] = temp[1]; } if (winCentre == 0 && winWidth == 0) { winWidth = 4095; winCentre = 4095 / 2; } } im.SetParameters(ref pixels16, imageWidth, imageHeight, winWidth, winCentre, true); string index = ""; foreach (string stt in dd.dicomInfo) { if (stt.Contains("Patient's Weight")) { index = stt; } } string wii = index.Split(':')[1]; foreach (string stt in dd.dicomInfo) { if (stt.Contains("Patient's Name")) { index = stt; } } string pn = index.Split(':')[1];; AForge.Imaging.Filters.Grayscale g1 = new Grayscale(0.2125, 0.7154, 0.0721); Bitmap imagew = g1.Apply(im.bmp); int thresholding = (int)((dd.windowWidth - dd.windowCentre) * 255 / dd.windowWidth); AForge.Imaging.Filters.Threshold thf = new AForge.Imaging.Filters.Threshold(thresholding); Bitmap ther = thf.Apply(imagew); BlobCounter blobCounter = new BlobCounter(ther); Blob[] blobs = blobCounter.GetObjects(ther, false); ImageStatistics img; AForge.Imaging.Filters.GrayscaleToRGB d1 = new GrayscaleToRGB(); Bitmap bm = d1.Apply(imagew); Edges s = new Edges(); Graphics gg = Graphics.FromImage(bm); string ss = null; Bitmap myImage = null; Blob b; int count = 0; string locc = ""; foreach (Blob blob in blobs) { img = new ImageStatistics(blob.Image); double perc = ((double)img.PixelsCountWithoutBlack / (double)img.PixelsCount) * 100; if (blob.Image.Size.Height > 20 && blob.Image.Size.Width > 20 && perc > 35) { b = blob; ImageStatistics st = new ImageStatistics(b.Image); Bitmap pp = s.Apply(b.Image); ChannelFiltering c = new ChannelFiltering(new IntRange(0, 255), new IntRange(0, 0), new IntRange(0, 0)); Bitmap pp2 = d1.Apply(pp); c.ApplyInPlace(pp2); pp2.MakeTransparent(Color.Black); gg.DrawImage(pp2, b.Rectangle); gg.Flush(); myImage = im.bmp.Clone(b.Rectangle, System.Drawing.Imaging.PixelFormat.Format24bppRgb); ss = ((double)(st.PixelsCountWithoutBlack) * (double)dd.pixelHeight * dd.pixelWidth).ToString(); locc = (b.Rectangle.Location.X * dd.pixelWidth).ToString() + "mm," + (b.Rectangle.Location.Y * dd.pixelHeight).ToString() + "mm"; count++; } }//end foreach bm.Save(filedir + FileUpload1.FileName + ".png", ImageFormat.Png); records r = new records(); recordsTableAdapters.recordsTableAdapter ta = new recordsTableAdapters.recordsTableAdapter(); ta.InsertRecord(pn, wii, FileUpload1.FileName, FileUpload1.FileName + ".png", "", ss, locc); } } }
private void ReadAndDisplayDicomFile(string fileName, string fileNameOnly) { dd.DicomFileName = fileName; bool result = dd.dicomFileReadSuccess; if (result == true) { imageWidth = dd.width; imageHeight = dd.height; bitDepth = dd.bitsAllocated; winCentre = dd.windowCentre; winWidth = dd.windowWidth; StatusLabel1.Text = fileName + ": " + imageWidth.ToString() + " X " + imageHeight.ToString(); StatusLabel1.Text += " " + bitDepth.ToString() + " bits per pixel"; userControl11.NewImage = true; Text = "DICOM Image Viewer: " + fileNameOnly; if (bitDepth == 16) { pixels16.Clear(); pixels8.Clear(); dd.GetPixels16(ref pixels16); byte[] buffer = new byte[pixels16.Count * 2]; byte[] temp; ByteConverter d = new ByteConverter(); int j = 0; for (int i = 0; i < pixels16.Count; i++) { temp = System.BitConverter.GetBytes(pixels16[i]); buffer[j++] = temp[0]; buffer[j++] = temp[1]; } if (winCentre == 0 && winWidth == 0) { winWidth = 4095; winCentre = 4095 / 2; } string index = ""; foreach (string s in dd.dicomInfo) { if (s.Contains("Image Number")) { index = s; } } userControl11.SetParameters(ref pixels16, imageWidth, imageHeight, winWidth, winCentre, true, this); if (processI && int.Parse(index.Split(':')[1]) > 9) { AForge.Imaging.Filters.Grayscale g1 = new Grayscale(0.2125, 0.7154, 0.0721); AForge.Imaging.Filters.BrightnessCorrection bC = new AForge.Imaging.Filters.BrightnessCorrection(brightness); bC.ApplyInPlace(userControl11.bmp); Bitmap image = g1.Apply(userControl11.bmp); thresholding = (int)((dd.windowWidth - dd.windowCentre) * 255 / dd.windowWidth) - trackBar2.Value; label1.Text = thresholding.ToString(); AForge.Imaging.Filters.Threshold thf = new AForge.Imaging.Filters.Threshold(thresholding); Bitmap ther = thf.Apply(image); BlobCounter blobCounter = new BlobCounter(ther); Blob[] blobs = blobCounter.GetObjects(ther, false); ImageStatistics img; AForge.Imaging.Filters.GrayscaleToRGB d1 = new GrayscaleToRGB(); Bitmap bm = d1.Apply(image); Edges s = new Edges(); Graphics gg = Graphics.FromImage(bm); string ss = null; Bitmap myImage = null; Blob b; int count = 0; listView1.Items.Clear(); mylesions.Clear(); Crop cut; Bitmap Ilesion = null; //System.Threading.Tasks.Parallel.ForEach(blobs, blob => foreach (Blob blob in blobs) { img = new ImageStatistics(blob.Image); double perc = ((double)img.PixelsCountWithoutBlack / (double)img.PixelsCount) * 100; textBox2.Text = perc.ToString(); if (blob.Image.Size.Height > 20 && blob.Image.Size.Width > 20 && perc > 35) { b = blob; cut = new Crop(b.Rectangle); Ilesion = g1.Apply(cut.Apply(userControl11.bmp)); ImageStatistics st = new ImageStatistics(b.Image); Bitmap pp = s.Apply(b.Image); ChannelFiltering c = new ChannelFiltering(new IntRange(0, 255), new IntRange(0, 0), new IntRange(0, 0)); Bitmap pp2 = d1.Apply(pp); c.ApplyInPlace(pp2); pp2.MakeTransparent(Color.Black); gg.DrawImage(pp2, b.Rectangle); gg.Flush(); myImage = userControl11.bmp.Clone(b.Rectangle, System.Drawing.Imaging.PixelFormat.Format24bppRgb); ss = ((double)(st.PixelsCountWithoutBlack) * (double)dd.pixelHeight * dd.pixelWidth).ToString(); ListViewItem lv = new ListViewItem(count.ToString()); lv.SubItems.Add(ss); lv.SubItems.Add(b.Rectangle.Location.X.ToString() + "," + b.Rectangle.Location.Y.ToString()); listView1.Items.Add(lv); Add adder = new Add(pp); Bitmap undashes = (Bitmap)Ilesion.Clone(); adder.ApplyInPlace(Ilesion); string locc = (b.Rectangle.Location.X * dd.pixelWidth).ToString() + "mm," + (b.Rectangle.Location.Y * dd.pixelHeight).ToString() + "mm"; mylesions.Add(new lesion((Bitmap)Ilesion.Clone(), ss, b.Rectangle.Location, locc, undashes)); count++; } } textBox1.Text = "tumor size= " + ss + " mm² *" + dd.pixelDepth.ToString() + "mm"; // host.NewDocument(bmp); // pictureBox2.Image = myImage; pictureBox1.Image = bm; pictureBox2.Image = Ilesion; } else { pictureBox1.Image = userControl11.bmp; } pictureBox1.Invalidate(); } //userControl11.increasecontrast(200); } else { if (dd.dicmFound == false) { MessageBox.Show("This does not seem to be a DICOM 3.0 file. Sorry, I can't open this."); } else if (dd.dicomDir == true) { MessageBox.Show("This seems to be a DICOMDIR file, and does not contain an image."); } else { MessageBox.Show("Sorry, I can't read a DICOM file with this Transfer Syntax\n" + "You may view the initial tags instead."); } //userControl11.SetParameters(ref pixels8, imageWidth, imageHeight, // winWidth, winCentre, true, this); } }
/// <summary> /// Convert a DepthImagePixel array to a bitmap. /// Bitmap is colorize if a gradient bitmap has been set, isolines are also added as an overlay /// </summary> /// <param name="sourceData">DepthImagePixel array (generated by Kinect device depth sensor)</param> protected override void Process(DepthImagePixel[] sourceData) { #if TRACE this.Log().Debug("New data received to process"); #endif Bitmap source = Utility.convertToBitmap(sourceData, (int)this.StartPoint.X, (int)this.StartPoint.Y, this.Height, this.Width, this.MinDepth, this.MaxDepth); // Apply a blur on source image (smothing isolines and output) Blur blur = new Blur(); source = blur.Apply(source); // Clone bitmap, final will be colorize, than isolines will be applied Bitmap final = source.Clone(new System.Drawing.Rectangle(0, 0, source.Width, source.Height), source.PixelFormat); // If gradient bitmap available colorize image if (this.Gradient != null) { ColorizedAlpha cAlpha = new ColorizedAlpha(this.Gradient); final = cAlpha.Apply(final); } else { // Convert isolines to rgb (to merge with final image) GrayscaleToRGB gtoRGB = new GrayscaleToRGB(); // apply the filter final = gtoRGB.Apply(final); } if (Isolines > 0) { // Generate isolines (startting at level 10, step 25) int level = (int)Math.Round((double)(255 / this.Isolines)); int step = level; // Isolines bitmap will receive every islone generated, then added to final image Bitmap isolines = new Bitmap(this.Width, this.Height, PixelFormat.Format8bppIndexed); while (level < 255) { // Every point over level will be set to black, otherwise white (easier and faster for edge detection) Threshold threshold = new Threshold(level); Bitmap temp = threshold.Apply(source); // Detect Edge using sobel alogorithmn //SobelEdgeDetector sobel = new SobelEdgeDetector(); Edges sobel = new Edges(); temp = sobel.Apply(temp); // Add edge bitmap to tempora Add filter = new Add(temp); //filter.SourcePercent = 0.6; // apply the filter filter.ApplyInPlace(isolines); // Set next level value level = level + step; } // Convert isolines to rgb (to merge with final image) GrayscaleToRGB gtoRGB = new GrayscaleToRGB(); // apply the filter Bitmap rgbIsoline = gtoRGB.Apply(isolines); // Add isolines to final image CustomMorph cMorph = new CustomMorph(rgbIsoline); cMorph.SourcePercent = 0.5; final = cMorph.Apply(final); } // Pass bitmap generated to UI (or other filter) OnOutputDataReady(new BitmapReadyEventArgs(final)); }
public static Bitmap DetectEdges(Bitmap image) { Edges edgeDetector = new Edges(); return(edgeDetector.Apply(image)); }