private void AllocateImagesNPP(Bitmap size) { int w = size.Width; int h = size.Height; if (inputImage8uC3 == null) { inputImage8uC1 = new NPPImage_8uC1(w, h); inputImage8uC3 = new NPPImage_8uC3(w, h); inputImage8uC4 = new NPPImage_8uC4(w, h); imageBayer = new NPPImage_32fC1(w, h); inputImage32f = new NPPImage_32fC3(w, h); noisyImage8u = new NPPImage_8uC3(w, h); noiseImage32f = new NPPImage_32fC3(w, h); resultImage8u = new NPPImage_8uC3(w, h); resultImage32f = new NPPImage_32fC3(w, h); return; } if (inputImage8uC3.Width >= w && inputImage8uC3.Height >= h) { inputImage8uC1.SetRoi(0, 0, w, h); inputImage8uC3.SetRoi(0, 0, w, h); inputImage8uC4.SetRoi(0, 0, w, h); imageBayer.SetRoi(0, 0, w, h); inputImage32f.SetRoi(0, 0, w, h); noisyImage8u.SetRoi(0, 0, w, h); noiseImage32f.SetRoi(0, 0, w, h); resultImage8u.SetRoi(0, 0, w, h); resultImage32f.SetRoi(0, 0, w, h); } else { inputImage8uC1.Dispose(); inputImage8uC3.Dispose(); inputImage8uC4.Dispose(); imageBayer.Dispose(); inputImage32f.Dispose(); noisyImage8u.Dispose(); noiseImage32f.Dispose(); resultImage8u.Dispose(); resultImage32f.Dispose(); inputImage8uC1 = new NPPImage_8uC1(w, h); inputImage8uC3 = new NPPImage_8uC3(w, h); inputImage8uC4 = new NPPImage_8uC4(w, h); imageBayer = new NPPImage_32fC1(w, h); inputImage32f = new NPPImage_32fC3(w, h); noisyImage8u = new NPPImage_8uC3(w, h); noiseImage32f = new NPPImage_32fC3(w, h); resultImage8u = new NPPImage_8uC3(w, h); resultImage32f = new NPPImage_32fC3(w, h); } }
private void CleanUp() { pictureBox_src.Image = null; pictureBox_dest.Image = null; hist_rb_src.Image = null; hist_g_src.Image = null; hist_b_src.Image = null; hist_rb_dest.Image = null; hist_g_dest.Image = null; hist_b_dest.Image = null; lbl_max.Text = "0"; _colorChannels = 0; if (src_c1 != null) { src_c1.Dispose(); } if (src_c3 != null) { src_c3.Dispose(); } if (src_c4 != null) { src_c4.Dispose(); } if (dest_c1 != null) { dest_c1.Dispose(); } if (dest_c4 != null) { dest_c4.Dispose(); } if (dest_c3 != null) { dest_c3.Dispose(); } }
private void btn_openImg_Click(object sender, EventArgs e) { OpenFileDialog ofd = new OpenFileDialog(); ofd.Filter = "Images|*.bmp;*.jpg;*.jpeg;*.tiff;*.tif;*.png;*.gif"; if (ofd.ShowDialog() != System.Windows.Forms.DialogResult.OK) { return; } bmp_src = new Bitmap(ofd.FileName); if (bmp_src.PixelFormat != PixelFormat.Format24bppRgb) { MessageBox.Show("Only 24-bit RGB images are supported!"); bmp_src = null; bmp_mask = null; bmp_res = null; if (npp_bmp_src != null) { npp_bmp_src.Dispose(); } if (npp_bmp_res != null) { npp_bmp_res.Dispose(); } if (npp_bmp_mask != null) { npp_bmp_mask.Dispose(); } if (d_bmp_src != null) { d_bmp_src.Dispose(); } if (d_bmp_res != null) { d_bmp_res.Dispose(); } if (d_bmp_mask != null) { d_bmp_mask.Dispose(); } return; } width = bmp_src.Width; height = bmp_src.Height; marker = new int[width * height]; bmp_res = new Bitmap(width, height, PixelFormat.Format32bppArgb); bmp_mask = new Bitmap(width, height, PixelFormat.Format8bppIndexed); SetPalette(bmp_mask); pictureBox_src.Image = bmp_src; selection.x = (int)Math.Ceiling(width * 0.1); selection.y = (int)Math.Ceiling(height * 0.1); selection.width = width - 2 * selection.x; selection.height = height - 2 * selection.y; if (npp_bmp_src != null) { npp_bmp_src.Dispose(); } if (npp_bmp_res != null) { npp_bmp_res.Dispose(); } if (npp_bmp_mask != null) { npp_bmp_mask.Dispose(); } if (d_bmp_src != null) { d_bmp_src.Dispose(); } if (d_bmp_res != null) { d_bmp_res.Dispose(); } if (d_bmp_mask != null) { d_bmp_mask.Dispose(); } NPPImage_8uC3 npp_temp = new NPPImage_8uC3(width, height); CudaPitchedDeviceVariable <uchar3> d_bmp_temp = new CudaPitchedDeviceVariable <uchar3>(npp_temp.DevicePointer, width, height, npp_temp.Pitch); npp_temp.CopyToDevice(bmp_src); npp_bmp_src = new NPPImage_8uC4(width, height); npp_bmp_res = new NPPImage_8uC4(width, height); npp_bmp_mask = new NPPImage_8uC1(width, height); d_bmp_src = new CudaPitchedDeviceVariable <uchar4>(npp_bmp_src.DevicePointer, width, height, npp_bmp_src.Pitch); d_bmp_res = new CudaPitchedDeviceVariable <uchar4>(npp_bmp_res.DevicePointer, width, height, npp_bmp_res.Pitch); d_bmp_mask = new CudaPitchedDeviceVariable <byte>(npp_bmp_mask.DevicePointer, width, height, npp_bmp_mask.Pitch); grabcut = new GrabCut(d_bmp_src, d_bmp_mask, width, height); grabcut.grabCutUtils.convertRGBToRGBA(d_bmp_src, d_bmp_temp, width, height); d_bmp_temp.Dispose(); npp_temp.Dispose(); }