예제 #1
0
    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);
            }
        }
    }
예제 #2
0
        public Bitmap edgeDetection()
        {
            Bitmap          colorImg      = (Bitmap)videoSourcePlayer1.GetCurrentVideoFrame();
            Grayscale       grayfilter    = new Grayscale(cr, cg, cb);
            GaussianBlur    blurFilter    = new GaussianBlur();
            GaussianSharpen sharpenFilter = new GaussianSharpen();
            Bitmap          originalImage;

            if (gausianToggle == 0)
            {
                originalImage = (Bitmap)grayfilter.Apply(colorImg);
            }
            else if (gausianToggle == 1)
            {
                originalImage = sharpenFilter.Apply((Bitmap)colorImg);
                originalImage = (Bitmap)grayfilter.Apply(originalImage);
            }
            else
            {
                originalImage = blurFilter.Apply((Bitmap)colorImg);
                originalImage = (Bitmap)grayfilter.Apply(originalImage);
            }
            switch (caseValue)
            {
            case 1:
                //canny
                scrollableImagePanel1.Image = originalImage;
                CannyEdgeDetector edgeDectector = new CannyEdgeDetector();
                edgeDectector.HighThreshold = (byte)cannyUpperThresholdSlider.Value;
                edgeDectector.LowThreshold  = (byte)cannyLowerThresholdSlider.Value;
                edgeDectector.ApplyInPlace(scrollableImagePanel1.Image);
                return((Bitmap)scrollableImagePanel1.Image);

            case 2:
                //gray scale
                scrollableImagePanel3.Image = originalImage;
                Grayscale customGrayScale = new Grayscale((cr * (graySlider.Value / 100)), (cb * (graySlider.Value / 100)), (cg * (graySlider.Value / 100)));
                originalImage = customGrayScale.Apply(colorImg);
                return(originalImage);

            case 3:
                //Black and White
                scrollableImagePanel2.Image = originalImage;
                Threshold thresholdFilter = new Threshold();
                thresholdFilter.ThresholdValue = hScrollBar1.Value;
                thresholdFilter.ApplyInPlace(scrollableImagePanel2.Image);
                return((Bitmap)scrollableImagePanel2.Image);

            case 4:
                //Mixed Color Edits
                scrollableImagePanel5.Image = colorImg;
                ChannelFiltering colorChannelFilter = new ChannelFiltering();
                colorChannelFilter.Red   = new IntRange(0, redSlider.Value);
                colorChannelFilter.Blue  = new IntRange(0, blueSlider.Value);
                colorChannelFilter.Green = new IntRange(0, greenSlider.Value);
                colorChannelFilter.ApplyInPlace((Bitmap)scrollableImagePanel5.Image);
                return((Bitmap)scrollableImagePanel5.Image);

            case 5:
                //Specific Color edits
                ColorFiltering colorFilter = new ColorFiltering();
                if (colorToggle == 1)
                {
                    Console.WriteLine("Red disabled");
                    colorFilter.Red   = new IntRange(0, 0);
                    colorFilter.Blue  = new IntRange(0, 255);
                    colorFilter.Green = new IntRange(0, 255);
                    colorFilter.Apply(colorImg);
                    originalImage = colorImg;
                    return(originalImage);
                }
                else if (colorToggle == 2)
                {
                    Console.WriteLine("Blue disabled");
                    colorFilter.Red   = new IntRange(0, 255);
                    colorFilter.Blue  = new IntRange(0, 0);
                    colorFilter.Green = new IntRange(0, 255);
                    colorFilter.Apply(colorImg);
                    originalImage = colorImg;
                    return(originalImage);
                }
                else if (colorToggle == 3)
                {
                    Console.WriteLine("Green disabled");
                    colorFilter.Red   = new IntRange(0, 255);
                    colorFilter.Blue  = new IntRange(0, 255);
                    colorFilter.Green = new IntRange(0, 0);
                    colorFilter.Apply(colorImg);
                    originalImage = colorImg;
                    return(originalImage);
                }
                else
                {
                    return(colorImg);
                }
            }
            return(originalImage);
        }
예제 #3
0
        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);
            }
        }