Esempio n. 1
0
        private void RGBFilter_Clicked(object sender, RoutedEventArgs e)
        {
            if (mainPhoto != null)
            {
                chf = new ChannelFiltering();

                // set channels' ranges to keep
                chf.Red   = new AForge.IntRange(int.Parse(RedIn.Text), int.Parse(RedOut.Text));
                chf.Green = new AForge.IntRange(int.Parse(GreenIn.Text), int.Parse(GreenOut.Text));
                chf.Blue  = new AForge.IntRange(int.Parse(BlueIn.Text), int.Parse(BlueOut.Text));

                // apply the filter
                System.Drawing.Bitmap tmp = chf.Apply((System.Drawing.Bitmap)mainPhoto.Clone());
                //BitmapImage tmpBmpIs = ToBitmapImage(tmp);

                /*RenderTargetBitmap rtb = new RenderTargetBitmap((int)Photography.ActualWidth, (int)Photography.ActualHeight, mainPhoto.HorizontalResolution, mainPhoto, PixelFormats.Pbgra32);
                 * rtb.Render(Photography);
                 *
                 * PngBitmapEncoder png = new PngBitmapEncoder();
                 * png.Frames.Add(BitmapFrame.Create(rtb));
                 * MemoryStream stream = new MemoryStream();
                 * png.Save(stream);
                 * System.Drawing.Bitmap image = (System.Drawing.Bitmap)System.Drawing.Image.FromStream(stream);*/

                Photography.Source = ToBitmapImage(tmp);

                UpdateHistograms(tmp);
                UpdateChannelPreviews(tmp);
            }
        }
Esempio n. 2
0
        Bitmap Filter(Bitmap bitmap, MarkerColor color)
        {
            var filter = new ChannelFiltering();

            filter.Red = filter.Green = filter.Blue = new IntRange(0, 0);

            switch (color)
            {
            case MarkerColor.Red:
                filter.Red = new IntRange(0, 255);
                break;

            case MarkerColor.Green:
                filter.Green = new IntRange(0, 255);
                break;

            case MarkerColor.Blue:
                filter.Blue = new IntRange(0, 255);
                break;

            case MarkerColor.White:
                filter.Red   = new IntRange(0, 255);
                filter.Green = new IntRange(0, 255);
                filter.Blue  = new IntRange(0, 255);
                break;

            default:
                throw new NotImplementedException();
            }

            return(filter.Apply(bitmap));
        }
Esempio n. 3
0
        public Bitmap RedMask(Bitmap img)
        {
            ChannelFiltering filter = new ChannelFiltering();

            filter.Red   = new AForge.IntRange(0, 255);
            filter.Green = new AForge.IntRange(100, 255);
            filter.Blue  = new AForge.IntRange(100, 255);
            return(filter.Apply(img));
        }
Esempio n. 4
0
        private void process_button_Click(object sender, EventArgs e)
        {
            //changes are made here

            // Channel filtering is more towards saturated range, it is focusing on whole channel
            var channelFilter = new ChannelFiltering();

            channelFilter.Red   = new AForge.IntRange(120, 229);
            channelFilter.Green = new AForge.IntRange(80, 221);
            channelFilter.Blue  = new AForge.IntRange(120, 183);
            var channelFilterOutput = channelFilter.Apply(_inputImage);

            pictureBoxOutput.Image = channelFilterOutput;
        }
Esempio n. 5
0
 public static Bitmap getAzul(Bitmap image)
 {
     try
     {
         AForge.Imaging.Filters.ChannelFiltering filter = new ChannelFiltering(new IntRange(0, 0), new IntRange(0, 0), new IntRange(0, 255));
         System.Drawing.Bitmap newImage = filter.Apply(image);
         return(newImage);
     }
     catch (ArgumentException ex)
     {
         MessageBox.Show("No se puede apllicar el filtro" + ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
         return(null);
     }
 }
Esempio n. 6
0
        private void applyfilter(int a, int b, int c)
        {
            copyimg = copyimg1;
            ChannelFiltering filter = new ChannelFiltering();

            filter.Red   = new IntRange(a, 255);
            filter.Green = new IntRange(b, 255);
            filter.Blue  = new IntRange(c, 255);
            try
            {
                copyimg = filter.Apply(copyimg);
                MainForm.getMainForm.pictureBox1ImagePreview.Image = copyimg;
            }
            catch (Exception ex)
            { }
        }
Esempio n. 7
0
        public mFilterARGBChannel(wDomain RedRange, wDomain GreenRange, wDomain BlueRange, bool isOut)
        {
            Red   = RedRange;
            Green = GreenRange;
            Blue  = BlueRange;
            IsOut = isOut;


            BitmapType = mFilter.BitmapTypes.None;

            Effect = new ChannelFiltering(new IntRange((int)Red.T0, (int)Red.T1), new IntRange((int)Green.T0, (int)Green.T1), new IntRange((int)Blue.T0, (int)Blue.T1));
            Effect.RedFillOutsideRange   = IsOut;
            Effect.GreenFillOutsideRange = IsOut;
            Effect.BlueFillOutsideRange  = IsOut;

            filter = Effect;
        }
Esempio n. 8
0
        // New frame event handler, which is invoked on each new available video frame
        private void video_NewFrame(object sender, NewFrameEventArgs eventArgs)
        {
            Invoke((MethodInvoker) delegate()
            {
                optChose = comboBox2.SelectedIndex;
            });

            Bitmap bmp    = (Bitmap)eventArgs.Frame.Clone();
            Bitmap bmpPrc = (Bitmap)eventArgs.Frame.Clone();

            switch (optChose)
            {
            case 0:
                Grayscale     filter0   = new Grayscale(0.2125, 0.7154, 0.0721);
                Bitmap        grayImage = filter0.Apply(bmpPrc);
                OtsuThreshold filter1   = new OtsuThreshold();
                pictureBox1.Image = bmp;
                pictureBox2.Image = filter1.Apply(grayImage);
                break;

            case 1:
                Sepia filter2 = new Sepia();
                pictureBox1.Image = bmp;
                pictureBox2.Image = filter2.Apply(bmpPrc);
                break;

            case 2:
                ChannelFiltering filter3 = new ChannelFiltering();
                filter3.Red       = new IntRange(0, 255);
                filter3.Green     = new IntRange(100, 255);
                filter3.Blue      = new IntRange(100, 255);
                pictureBox1.Image = bmp;
                pictureBox2.Image = filter3.Apply(bmpPrc);
                break;

            case 3:
                HSLFiltering filter4 = new HSLFiltering();
                filter4.Hue             = new IntRange(340, 20);
                filter4.UpdateLuminance = false;
                filter4.UpdateHue       = false;
                pictureBox1.Image       = bmp;
                pictureBox2.Image       = filter4.Apply(bmpPrc);
                break;
            }
        }
Esempio n. 9
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);
        }
Esempio n. 10
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);
            }
        }
    }
Esempio n. 11
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);
            }
        }