private void Magic2(object sender, EventArgs e) { Image <Gray, Byte> tmp = InputBGR.Convert <Gray, Byte>(); Image <Gray, Byte> new_mask = tmp.CopyBlank(); CvInvoke.BitwiseXor(CurNBM.BodyMask, newMask.Convert <Gray, Byte>().ThresholdBinary(new Gray(1), new Gray(255)), new_mask); tmp = tmp.Copy(new_mask); VectorOfVectorOfPoint vvop = ImgProcTools.EdgeDetection.SimplestEdgeDetection(tmp.ThresholdBinary(new Gray(1), new Gray(255))); List <NeuronBodyMask> newNBM = NeuronSeparation.Masks.GetNeuronBodyMasks(NeuronSeparation.Converter.VVOPToListOfVOP(vvop)); NBM.InsertRange(NBM_id, newNBM); NBM.RemoveAt(NBM_id); }
public object[] PerformRotationCompare(double angulo, double scalex, double scaley, ref int tx, ref int ty, double skX = 0, double skY = 0, double repairFactor = 0.95) { SystemException exception = null; Image <Rgba, byte> two = null; Image <Rgba, byte> one = null; Mat resultMat = null; Image <Rgba, byte> canvas = null; Mat destiny = null; Mat compare = null; object[] array = new object[6]; double raidus = 0; // MCvMoments onemoment; // MCvMoments twomoment; int width = 0; int height = 0; bool repairTX = false; bool repairTY = false; try { two = UITwo; // one = this.imgUtil.expandedOne[0]; one = UIOne; performRotateScale(angulo, scalex, scaley, ref one); performSkew(skX, skY, ref one); } catch (Exception ex) { exception = new SystemException(ex.Message + " at Module#1.1"); } try { if (exception != null) { throw new Exception(exception.Message); } //determine bigger between one and two width = GetBiggerWidth(ref two, ref one); height = GetBiggerHeight(ref two, ref one); canvas = new Image <Rgba, byte>(width, height, imgUtil.pitchBlack); //make canvas from bigger and copy the smaller into this canvas canvas = MakeCanvas(ref canvas, out raidus); } catch (Exception ex) { exception = new SystemException(ex.Message + " at Module#1.2"); } try { if (exception != null) { throw new Exception(exception.Message); } two = canvas.CopyBlank(); destiny = performTranslate(ref tx, ref ty, repairFactor, ref two, ref one, ref repairTX, ref repairTY); } catch (Exception ex) { exception = new SystemException(ex.Message + " at Module#1.2"); } two?.Dispose(); one?.Dispose(); try { if (exception != null) { throw new Exception(exception.Message); } one = UITwo; two = canvas.CopyBlank(); //make canvas from bigger again // Copy the bigger into the canvas Point middle; middle = GetMiddlePointCanvas(raidus, ref one); Copy(ref middle, ref two, ref one); compare = two.Mat.Clone(); // two.Dispose(); resultMat = new Mat(); CvInvoke.BitwiseXor(compare, destiny, resultMat, null);// Emgu.CV.CvEnum.CmpType.Equal); // two = resultMat.ToImage<Rgba, byte>(); int[] counts = resultMat.ToImage <Rgba, byte>().CountNonzero(); List <int> cnt = new List <int>(counts); array[1] = cnt.ToArray(); Mat sumaImg = new Mat(); CvInvoke.Subtract(compare, destiny, sumaImg); //.ass.ToImage<Rgba,byte>().Add(destiny.ToImage<Rgba,byte>()).Mat; array[0] = sumaImg; } catch (Exception ex) { string previous = string.Empty; if (exception != null) { previous = exception?.Message + " +++ "; } exception = new SystemException(previous + ex.Message + " at Module#2"); } destiny?.Dispose(); compare?.Dispose(); resultMat?.Dispose(); two?.Dispose(); canvas?.Dispose(); array[3] = exception; array[4] = repairTX; array[5] = repairTY; return(array); }
public void Mask(Mat input, Mat mask, Mat output) { mask.ConvertTo(mask, DepthType.Cv8U); CvInvoke.BitwiseXor(output, output, output); input.CopyTo(output, mask); }
public object[] PerformRotationCompareFUNCIONA(double angulo, double scalex, double scaley, int tx, int ty, double skX = 0, double skY = 0) { Image <Rgba, byte> two = null; Image <Rgba, byte> one = null; Mat resultMat = new Mat(); Mat destiny = null; Mat compare = null; object[] array = null; double raidus = 0; object suma = null; object count = null; // bool firstStepOk = false; try { //VOLVI A CAMBIARLOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO//////////////////////// // one = imgUtil.expandedOne[0]; one = imgUtil.expandedOne[0]; two = UITwo; // one = UIOne; performRotateScale(angulo, scalex, scaley, ref one); performSkew(skX, skY, ref one); //determine bigger between one and two int width = GetBiggerWidth(ref two, ref one); int height = GetBiggerHeight(ref two, ref one); Image <Rgba, byte> canvas = new Image <Rgba, byte>(width, height, imgUtil.pitchBlack); // Image<Rgba, byte>[] biggerSmaller = GetBiggerSmallerImages(ref UITwo, ref one); //make canvas from bigger and copy the smaller into this canvas //int area = (biggerSmaller[0]).Height * (biggerSmaller[0]).Width; two = MakeCanvas(ref canvas, out raidus); canvas.Dispose(); ///CAMBIE ESTO Point middle = GetMiddlePointCanvas(raidus, ref one); // Point original = new Point(middle.X, middle.Y); middle.X = tx; middle.Y = ty; Copy(ref middle, ref two, ref one); //get Mat destiny = two.Mat.Clone(); // firstStepOk = true; } catch (Exception ex) { } one?.Dispose(); try { one = UITwo; two = two.CopyBlank(); //make canvas from bigger again // Copy the bigger into the canvas Point middle = GetMiddlePointCanvas(raidus, ref one); Copy(ref middle, ref two, ref one); compare = two.Mat.Clone(); two.Dispose(); object result = null; CvInvoke.BitwiseXor(compare, destiny, resultMat, null); // Emgu.CV.CvEnum.CmpType.Equal); // CvInvoke.Subtract(compare, destiny, resultMat); // CvInvoke.BitwiseAnd(compare, destiny, resultMat, null);// Emgu.CV.CvEnum.CmpType.Equal); // CvInvoke.Compare(compare, destiny, resultMat, Emgu.CV.CvEnum.CmpType.Equal);// Emgu.CV.CvEnum.CmpType.Equal); // CvInvoke.Pow(resultMat, 2, resultMat); two = resultMat.ToImage <Rgba, byte>(); suma = two.GetSum(); count = two.CountNonzero(); int area = Convert.ToInt32(1e4); // (count as int[])[3] = area; array = new object[] { null, count, suma }; Mat sumaImg = new Mat(); CvInvoke.Add(compare, destiny, sumaImg);//.ass.ToImage<Rgba,byte>().Add(destiny.ToImage<Rgba,byte>()).Mat; result = sumaImg; //result = resultMat; array[0] = result; // result = two.Mat.Clone(); // CvInvoke.Subtract(compare, destiny, resultMat); } catch (Exception ex) { } destiny?.Dispose(); compare?.Dispose(); resultMat?.Dispose(); two?.Dispose(); return(array); }
static public void EdgeXoringImage(String path, out List <int> indices_horizontal, out List <int> indices_vertical) { indices_horizontal = new List <int>(); indices_vertical = new List <int>(); Image <Gray, byte> eimage = new Image <Gray, byte>(path); int height = eimage.Height; int width = eimage.Width; Image <Gray, byte> edge_image = new Image <Gray, byte>(eimage.Width, eimage.Height); CvInvoke.Canny(eimage, edge_image, 50, 100); eimage = edge_image; Image <Gray, byte> image2 = new Image <Gray, byte>(path); Image <Gray, byte> edge_image2 = new Image <Gray, byte>(image2.Width, image2.Height); CvInvoke.Canny(image2, edge_image2, 50, 100); image2 = edge_image2; Image <Gray, byte> original = new Image <Gray, byte>(path); Image <Gray, byte> edge_original = new Image <Gray, byte>(original.Width, original.Height); CvInvoke.Canny(original, edge_original, 50, 100); original = edge_original; Dictionary <int, double> horizontal_values = new Dictionary <int, double>(); Dictionary <int, double> vertical_values = new Dictionary <int, double>(); Dictionary <int, int> trial = new Dictionary <int, int>(); int i = 1; for (i = 1; i < height; i++) { Image <Gray, byte> row = new Image <Gray, byte>(1, eimage.Width); CvInvoke.cvGetRow(eimage, row, 0); Image <Gray, byte> xor_image = new Image <Gray, byte>(eimage.Width, eimage.Height); Rectangle rect = new Rectangle(0, 1, eimage.Width, eimage.Height); eimage.ROI = rect; Image <Gray, byte> gray = eimage.Convert <Gray, byte>(); Image <Gray, byte> gray_row = row.Convert <Gray, byte>(); eimage = gray.ConcateVertical(gray_row); CvInvoke.BitwiseXor(original, eimage, xor_image); Gray gray_sum = xor_image.GetSum(); double intensity = gray_sum.Intensity; vertical_values.Add(i, intensity); } for (i = 1; i < width; i++) { Image <Gray, byte> column = new Image <Gray, byte>(image2.Height, 1); CvInvoke.cvGetCol(image2, column, 0); Image <Gray, byte> xor_image2 = new Image <Gray, byte>(image2.Height, image2.Width); Rectangle rect2 = new Rectangle(1, 0, image2.Width, image2.Height); image2.ROI = rect2; Image <Gray, byte> gray2 = image2.Convert <Gray, byte>(); Image <Gray, byte> gray_col = column.Convert <Gray, byte>(); image2 = gray2.ConcateHorizontal(gray_col); CvInvoke.BitwiseXor(original, image2, xor_image2); Gray gray_sum2 = xor_image2.GetSum(); double intensity2 = gray_sum2.Intensity; horizontal_values.Add(i, intensity2); } var min_vertical = vertical_values.Values.Min(); var min_horizontal = horizontal_values.Values.Min(); if (min_horizontal != 0) { Console.WriteLine("No complete Dark in Horizontal Direction"); } if (min_vertical != 0) { Console.WriteLine("No complete Dark in Vertical Direction"); } var dictval = from x in horizontal_values where x.Value == min_horizontal select x; foreach (KeyValuePair <int, double> values in dictval) { int key = values.Key; indices_horizontal.Add(key); } var dictval2 = from x in vertical_values where x.Value == min_vertical select x; foreach (KeyValuePair <int, double> values in dictval2) { int key = values.Key; indices_vertical.Add(key); } }