public LinkedList <ProcessingImage> getAllProcessingImage() { LinkedList <ProcessingImage> proImages = new LinkedList <ProcessingImage>(); DataSet dataset = baseDao.getAllEntities("tb_image"); int count = 0; if (null != dataset && (count = dataset.Tables[0].Rows.Count) > 0) { int i = 0; for (i = 0; i < count; i++) { ProcessingImage proImage = new ProcessingImage(); proImage.Id = getIntValue(dataset, i, "id"); proImage.Name = getValue(dataset, i, "name"); proImage.Image = getImageValue(dataset, i, "image"); proImage.Up = getBoolValue(dataset, i, "up"); proImage.Down = getBoolValue(dataset, i, "down"); proImage.Left = getBoolValue(dataset, i, "left"); proImage.Right = getBoolValue(dataset, i, "right"); proImages.AddLast(proImage); } } return(proImages); }
public ProcessingImage filter(ProcessingImage inputImage) { ProcessingImage outputImage = new ProcessingImage(); outputImage.copyAttributesAndAlpha(inputImage); outputImage.addWatermark(String.Format("conv watermark, dim: {0}", dim)); float[,] convMatrix = new float[dim, dim]; for (int i = 0; i < dim; i++) { for (int j = 0; j < dim; j++) { convMatrix[i, j] = (float)(1.0 / (dim * dim)); } } if (inputImage.grayscale) { byte[,] outputGray = new byte[inputImage.getSizeY(), inputImage.getSizeX()]; byte[,] inputGray = inputImage.getGray(); for (int y = dim / 2; y < inputImage.getSizeY() - dim / 2; y++) { for (int x = dim / 2; x < inputImage.getSizeX() - dim / 2; x++) { outputGray[y, x] = applyConv(x, y, inputGray, convMatrix); } } outputImage.setGray(outputGray); } else { byte[,] outputRed = new byte[inputImage.getSizeY(), inputImage.getSizeX()]; byte[,] outputGreen = new byte[inputImage.getSizeY(), inputImage.getSizeX()]; byte[,] outputBlue = new byte[inputImage.getSizeY(), inputImage.getSizeX()]; byte[,] inputRed = inputImage.getRed(); byte[,] inputGreen = inputImage.getGreen(); byte[,] inputBlue = inputImage.getBlue(); for (int y = dim / 2; y < inputImage.getSizeY() - dim / 2; y++) { for (int x = dim / 2; x < inputImage.getSizeX() - dim / 2; x++) { outputRed[y, x] = applyConv(x, y, inputRed, convMatrix); outputGreen[y, x] = applyConv(x, y, inputGreen, convMatrix); outputBlue[y, x] = applyConv(x, y, inputBlue, convMatrix); } } outputImage.setRed(outputRed); outputImage.setGreen(outputGreen); outputImage.setBlue(outputBlue); } return(outputImage); }
public ProcessingImage filter(ProcessingImage inputImage) { ProcessingImage outputImage = new ProcessingImage(); outputImage.copyAttributesAndAlpha(inputImage); outputImage.addWatermark(String.Format("sobel watermark")); const int dim = 3; float[,] convMatrixGx = new float[dim, dim] { { 1, 0, -1 }, { 2, 0, -2 }, { 1, 0, -1 } }; float[,] convMatrixGy = new float[dim, dim] { { 1, 2, 1 }, { 0, 0, 0 }, { -1, -2, -1 } }; byte[,] inputLuminance = inputImage.getLuminance(); byte[,] outputGray = new byte[inputImage.getSizeY() - (dim - 1), inputImage.getSizeX() - (dim - 1)]; for (int y = dim / 2; y < inputImage.getSizeY() - dim / 2; y++) { for (int x = dim / 2; x < inputImage.getSizeX() - dim / 2; x++) { float resx = applyConv(x, y, inputLuminance, convMatrixGx); float resy = applyConv(x, y, inputLuminance, convMatrixGy); double r = Math.Sqrt((resx * resx) + (resy * resy)); if (r < 0) { r = 0; } if (r > 255) { r = 255; } outputGray[y - dim / 2, x - dim / 2] = (byte)r; } } outputImage.setSizeX(inputImage.getSizeX() - (dim - 1)); outputImage.setSizeY(inputImage.getSizeY() - (dim - 1)); outputImage.setGray(outputGray); return(outputImage); }
private decimal computeWorkingNumberX(XialiaoOrderItem xialiaoOrderItem, TypeOfProcess workingNameX, ProcessingImage workingDiagramX) { decimal value = 0; OrderItem orderItem = xialiaoOrderItem.OrderItem; if (null == workingNameX || null == workingDiagramX) { return(0); } else { TypeOfProcess typePro = workingNameX; if (Parameter.PACKAGE.Equals(typePro.Unit)) { value = orderItem.Package; } else if (Parameter.METER.Equals(typePro.Unit)) { ProcessingImage proImage = workingDiagramX; int length = 0, width = 0, package = 0; length = Util.getValueOfLWT2(orderItem.Length); width = Util.getValueOfLWT2(orderItem.Width); package = xialiaoOrderItem.UsePackage; decimal sum = 0; if (proImage.Up) { sum += ((decimal)length) / 1000 * package; } if (proImage.Down) { sum += ((decimal)length) / 1000 * package; } if (proImage.Left) { sum += ((decimal)width) / 1000 * package; } if (proImage.Right) { sum += ((decimal)width) / 1000 * package; } value = decimal.Round(sum, Parameter.NUMBER_MANTISSA); } else { MessageBox.Show("不认识的加工类型", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); } } return(value); }
public void Execute() { ProcessedImage = new SKBitmap(ProcessingImage.Width, ProcessingImage.Height); for (int x = 0; x < ProcessingImage.Width; ++x) { for (int y = 0; y < ProcessingImage.Height; ++y) { SKColor color = ProcessingImage.GetPixel(x, y); double grayscale = color.Red * 0.3 + color.Green * 0.59 + color.Blue * 0.11; byte value = (byte)grayscale; ProcessedImage.SetPixel(x, y, new SKColor(value, value, value, color.Alpha)); } } }
public void Execute() { ProcessedImage = new SKBitmap(ProcessingImage.Width, ProcessingImage.Height); for (int x = 0; x < ProcessingImage.Width; x++) { for (int y = 0; y < ProcessingImage.Height; y++) { SKColor pixel = ProcessingImage.GetPixel(x, y); if (x == 0 || y == 0 || x == ProcessingImage.Width - 1 || y == ProcessingImage.Height - 1) { ProcessedImage.SetPixel(x, y, pixel); } else { // 3x3 mask List <byte> mask = new List <byte> { ProcessingImage.GetPixel(x - 1, y - 1).Red, ProcessingImage.GetPixel(x - 1, y).Red, ProcessingImage.GetPixel(x - 1, y + 1).Red, ProcessingImage.GetPixel(x, y - 1).Red, ProcessingImage.GetPixel(x, y).Red, ProcessingImage.GetPixel(x, y + 1).Red, ProcessingImage.GetPixel(x + 1, y - 1).Red, ProcessingImage.GetPixel(x + 1, y).Red, ProcessingImage.GetPixel(x + 1, y + 1).Red }; byte average = 0; foreach (byte px in mask) { average += px; } average /= 9; ProcessedImage.SetPixel(x, y, new SKColor(average, average, average, pixel.Alpha)); } } } }
public async Task <List <OcrResults> > PostDocument([FromBody] TextRecognitionSettings inputSettings) { var documentPath = FileHelper.GetProcessingDocumentPath(inputSettings.FileName); var language = LanguageHelper.GetLanguageByString(inputSettings.Language); var results = new List <OcrResults>(); if (FileHelper.IsPdf(documentPath)) { var pdf = new ProcessingPdf(documentPath, language); pdf.GeneratePagesForPdfDoc(); results = pdf.Process(inputSettings); } else { var img = new ProcessingImage(documentPath, language); results = img.Process(inputSettings); } FileHelper.CleanUpFilesByName(documentPath); return(results); }
public void Execute() { ProcessedImage = new SKBitmap(ProcessingImage.Info); for (int x = 0; x < ProcessingImage.Width; x++) { for (int y = 0; y < ProcessingImage.Height; y++) { SKColor pixel = ProcessingImage.GetPixel(x, y); float distance = (float)Math.Sqrt( ((int)pixel.Red - (int)Color.Red) * ((int)pixel.Red - (int)Color.Red) + ((int)pixel.Green - (int)Color.Green) * ((int)pixel.Green - (int)Color.Green) + ((int)pixel.Blue - (int)Color.Blue) * ((int)pixel.Blue - (int)Color.Blue) ); ProcessedImage.SetPixel(x, y, distance <= EstimatedDistance ? new SKColor(0, 0, 0, pixel.Alpha) : new SKColor(255, 255, 255, pixel.Alpha)); } } }
private ProcessingImage ConstructImage(DataGridViewRow row) { ProcessingImage proImage = new ProcessingImage(); if ("".Equals(row.Cells["id"].Value.ToString())) { proImage.Id = 0; } else { proImage.Id = int.Parse(row.Cells["id"].Value.ToString()); } proImage.Name = row.Cells["name"].Value.ToString(); proImage.Image = Util.byteArrayToImage((byte[])row.Cells["image"].Value); // 不能采用row.Cells["image"].Value as Image;的方式 proImage.Up = getBoolValue(row.Cells["up"].Value.ToString()); proImage.Down = getBoolValue(row.Cells["down"].Value.ToString()); proImage.Left = getBoolValue(row.Cells["left"].Value.ToString()); proImage.Right = getBoolValue(row.Cells["right"].Value.ToString()); return(proImage); }
public MessageLocal saveOrUpdateProcessingImage(ProcessingImage processingImage) { MessageLocal msg = new MessageLocal(); byte[] buffByte = Util.imageToByteArray(processingImage.Image); SqlParameter[] prams = { database.MakeInParam("@id", SqlDbType.Int, 0, processingImage.Id), database.MakeInParam("@name", SqlDbType.NVarChar, 20, processingImage.Name), database.MakeInParam("@image", SqlDbType.Image, 0, buffByte), database.MakeInParam("@up", SqlDbType.Bit, 0, processingImage.Up), database.MakeInParam("@down", SqlDbType.Bit, 0, processingImage.Down), database.MakeInParam("@left", SqlDbType.Bit, 0, processingImage.Left), database.MakeInParam("@right", SqlDbType.Bit, 0, processingImage.Right), new SqlParameter("@message", SqlDbType.NVarChar, 20), new SqlParameter("rval", SqlDbType.Int, 4) }; prams[prams.Length - 2].Direction = ParameterDirection.Output; prams[prams.Length - 1].Direction = ParameterDirection.ReturnValue; return(baseDao.runProcedure("saveOrUpdate_tb_image", prams, "tb_image")); }
public void Execute() { ProcessedImage = new SKBitmap(ProcessingImage.Width, ProcessingImage.Height); for (int x = 0; x < ProcessingImage.Width; x++) { for (int y = 0; y < ProcessingImage.Height; y++) { SKColor pixel = ProcessingImage.GetPixel(x, y); if (x == 0 || y == 0 || x == ProcessingImage.Width - 1 || y == ProcessingImage.Height - 1) { ProcessedImage.SetPixel(x, y, pixel); } else { // 3x3 mask List <byte> mask = new List <byte> { ProcessingImage.GetPixel(x - 1, y - 1).Red, ProcessingImage.GetPixel(x - 1, y).Red, ProcessingImage.GetPixel(x - 1, y + 1).Red, ProcessingImage.GetPixel(x, y - 1).Red, ProcessingImage.GetPixel(x, y).Red, ProcessingImage.GetPixel(x, y + 1).Red, ProcessingImage.GetPixel(x + 1, y - 1).Red, ProcessingImage.GetPixel(x + 1, y).Red, ProcessingImage.GetPixel(x + 1, y + 1).Red }; mask.Sort(); ProcessedImage.SetPixel(x, y, new SKColor(mask[4], mask[4], mask[4], pixel.Alpha)); } } } }
public ProcessingImage filter(ProcessingImage inputImage) { ProcessingImage outputImage = new ProcessingImage(); outputImage.copyAttributesAndAlpha(inputImage); outputImage.addWatermark(String.Format("Active contour filter watermark")); double k = 0.001; int radius = 25; byte[,] inputLuminance = inputImage.getLuminance(); int centerX = inputImage.getSizeX() / 2; int centerY = inputImage.getSizeY() / 2; int[,] outputImageResult = new int[inputImage.getSizeY(), inputImage.getSizeX()]; outputImageResult[centerY, centerX] = 255; Point[] points = new Point[numPoints]; int n = 0; for (double i = 0; i < 2 * Math.PI && n < numPoints; i += (2 * Math.PI) / numPoints) { double sinRes = Math.Sin(i); double cosRes = Math.Cos(i); points[n] = new Point(); points[n].x = centerY + (radius * sinRes); points[n].y = centerX + (radius * cosRes); n++; } for (int i = 0; i < numPoints; i++) { outputImageResult[(int)points[i].y, (int)points[i].x] = 255; } for (int s = 0; s < numSteps; s++) { for (int i = 0; i < numPoints; i++) { int up_i = i + 1; int down_i = i - 1; if (up_i >= numPoints - 1) { up_i = 0; } if (down_i < 0) { down_i = numPoints - 1; } double dx1 = points[down_i].x - points[i].x; double dx2 = points[up_i].x - points[i].x; double dy1 = points[down_i].y - points[i].y; double dy2 = points[up_i].y - points[i].y; points[i].accelX = k * dx1 + k * dx2; //elastic force, we approximate F=ma with a mass of 1 points[i].accelY = k * dy1 + k * dy2; // sum of forces that act on the object on both axes points[i].speedY = points[i].speedY + points[i].accelY; points[i].speedX = points[i].speedX + points[i].accelX; if (points[i].speedY > 2) { points[i].speedY = 2; } if (points[i].speedY < -2) { points[i].speedY = -2; } if (points[i].speedX > 2) { points[i].speedX = 2; } if (points[i].speedX < -2) { points[i].speedX = -2; } points[i].y = (points[i].y + points[i].speedY); points[i].x = (points[i].x + points[i].speedX); } } for (int i = 0; i < numPoints; i++) { if ((int)points[i].y >= 0 && (int)points[i].x >= 0 && (int)points[i].x < outputImage.getSizeX() && (int)points[i].y < outputImage.getSizeY()) { outputImageResult[(int)points[i].y, (int)points[i].x] = 100; } } ////////////////////////////////// to byte byte[,] outputGray = new byte[outputImageResult.GetLength(0), outputImageResult.GetLength(1)]; for (int y = 0; y < outputGray.GetLength(0); y++) { for (int x = 0; x < outputGray.GetLength(1); x++) { float r = outputImageResult[y, x]; if (r < 0) { r = 0; } if (r > 255) { r = 255; } outputGray[y, x] = (byte)r; } } outputImage.setSizeX(outputGray.GetLength(1)); outputImage.setSizeY(outputGray.GetLength(0)); outputImage.setGray(outputGray); return(outputImage); }
//刷新ColumnNumber[1-3] private void refreshColumnNumberX(object sender, DataGridViewCellEventArgs e, string columnName) { int index = int.Parse(columnName.Substring(columnName.Length - 1, 1)); string name = "ColumnName" + index; string diagram = "ColumnDiagram" + index; string number = "ColumnNumber" + index; decimal value = 0; if (-1 == columnName.IndexOf("ColumnName")) { if (Util.isDecimal(getFormattedValue(e, number))) { value = -decimal.Parse(getFormattedValue(e, number)); } } if (null == dataGridViewItem.Rows[e.RowIndex].Cells[name].Tag || null == dataGridViewItem.Rows[e.RowIndex].Cells[diagram].Tag) { dataGridViewItem.Rows[e.RowIndex].Cells[number].Value = 0; } else { TypeOfProcess typePro = (TypeOfProcess)dataGridViewItem.Rows[e.RowIndex].Cells[name].Tag; if (Parameter.PACKAGE.Equals(typePro.Unit)) { dataGridViewItem.Rows[e.RowIndex].Cells[number].Value = getFormattedValue(e, "ColumnPackage"); } else if (Parameter.METER.Equals(typePro.Unit)) { ProcessingImage proImage = (ProcessingImage)dataGridViewItem.Rows[e.RowIndex].Cells[diagram].Tag; int length = 0, width = 0, package = 0; if (Util.isLengthOrWidth(getFormattedValue(e, "ColumnLength"))) { length = Util.getValueOfLWT2(getFormattedValue(e, "ColumnLength")); } if (Util.isLengthOrWidth(getFormattedValue(e, "ColumnWidth"))) { width = Util.getValueOfLWT2(getFormattedValue(e, "ColumnWidth")); } if (Util.isDigital(getFormattedValue(e, "ColumnPackage"))) { package = int.Parse(getFormattedValue(e, "ColumnPackage")); } decimal sum = 0; if (proImage.Up) { sum += ((decimal)length) / 1000 * package; } if (proImage.Down) { sum += ((decimal)length) / 1000 * package; } if (proImage.Left) { sum += ((decimal)width) / 1000 * package; } if (proImage.Right) { sum += ((decimal)width) / 1000 * package; } dataGridViewItem.Rows[e.RowIndex].Cells[number].Value = decimal.Round(sum, Parameter.NUMBER_MANTISSA); } else { MessageBox.Show("不认识的加工类型", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); } value = Util.getDecimalValue(dataGridViewItem.Rows[e.RowIndex].Cells[number].FormattedValue.ToString()) + value; insertIntoStats((TypeOfProcess)dataGridViewItem.Rows[e.RowIndex].Cells[name].Tag, dataGridViewItem.Rows[e.RowIndex].Cells["ColumnThickness"].Value.ToString(), value); } }
public void Execute() { ProcessedImage = new SKBitmap(ProcessingImage.Width, ProcessingImage.Height); double[] GreyLevels = new double[256]; double GlSum = 0; for (int x = 0; x < ProcessingImage.Width; x++) { for (int y = 0; y < ProcessingImage.Height; y++) { SKColor pixel = ProcessingImage.GetPixel(x, y); if (pixel.Alpha != 0) { GreyLevels[pixel.Red] += 1; } } } for (int index = 0; index < 256; index++) { GreyLevels[index] /= (ProcessingImage.Width * ProcessingImage.Height); GlSum += GreyLevels[index]; } double FirstClassProb, SecondClassProb; double FirstClassMean, SecondClassMean, MeanGrey; double FirstSigma, SecondSigma, MaxSigma = 0; double zwSigma, imSigma; int BestThreshold = 0; for (int Threshold = 1; Threshold < 255; Threshold++) { FirstClassMean = 0; SecondClassMean = 0; FirstClassProb = 0; SecondClassProb = 0; FirstSigma = 0; SecondSigma = 0; for (int index = 0; index <= Threshold; index++) { FirstClassProb += GreyLevels[index]; } SecondClassProb = GlSum - FirstClassProb; for (int index = 0; index < 256; index++) { if (index <= Threshold) { FirstClassMean += index * GreyLevels[index]; } else { SecondClassMean += index * GreyLevels[index]; } } FirstClassMean = ((double)1 / FirstClassProb) * FirstClassMean; SecondClassMean = ((double)1 / SecondClassProb) * SecondClassMean; MeanGrey = FirstClassMean * FirstClassProb + SecondClassProb * SecondClassMean; for (int index = 0; index < 256; index++) { if (index <= Threshold) { FirstSigma += GreyLevels[index] * System.Math.Pow(index - FirstClassMean, 2); } else { SecondSigma += GreyLevels[index] * System.Math.Pow(index - SecondClassMean, 2); } } zwSigma = FirstClassProb * System.Math.Pow(FirstClassMean - MeanGrey, 2) + SecondClassProb * System.Math.Pow(SecondClassMean - MeanGrey, 2); imSigma = FirstClassProb * FirstSigma + SecondClassProb * SecondSigma; double val = zwSigma / imSigma; if (val > MaxSigma) { MaxSigma = val; BestThreshold = Threshold; } } for (int y = 0; y < ProcessingImage.Height; y++) { for (int x = 0; x < ProcessingImage.Width; x++) { SKColor pixel = ProcessingImage.GetPixel(x, y); if (pixel.Red >= BestThreshold) { ProcessedImage.SetPixel(x, y, new SKColor(255, 255, 255, pixel.Alpha)); } else { ProcessedImage.SetPixel(x, y, new SKColor(0, 0, 0, pixel.Alpha)); } } } }
public ProcessingImage filter(ProcessingImage inputImage) { ProcessingImage outputImage = new ProcessingImage(); outputImage.copyAttributesAndAlpha(inputImage); outputImage.addWatermark(String.Format("canny watermark")); float[,] gaussianMatrix = generateGaussianMatrix(); byte[,] inputLuminance = inputImage.getLuminance(); float[,] outputImageGauss = new float[inputImage.getSizeY() - (gaussDim - 1), inputImage.getSizeX() - (gaussDim - 1)]; /////////////////////////////////// input image -> GAUSS -> output image Gauss for (int y = gaussDim / 2; y < inputImage.getSizeY() - gaussDim / 2; y++) { for (int x = gaussDim / 2; x < inputImage.getSizeX() - gaussDim / 2; x++) { float r = applyConv(x, y, inputLuminance, gaussianMatrix); /*if (r < 0) r = 0; * if (r > 255) r = 255;*/ outputImageGauss[y - gaussDim / 2, x - gaussDim / 2] = r; } } /////////////////////////////////// output image Gauss -> SOBEL -> output image Sobel const int sobelDim = 3; float[,] convMatrixGx = new float[sobelDim, sobelDim] { { 1, 0, -1 }, { 2, 0, -2 }, { 1, 0, -1 } }; float[,] convMatrixGy = new float[sobelDim, sobelDim] { { 1, 2, 1 }, { 0, 0, 0 }, { -1, -2, -1 } }; float[,] outputImageSobel = new float[outputImageGauss.GetLength(0) - (sobelDim - 1), outputImageGauss.GetLength(1) - (sobelDim - 1)]; DIRECTION[,] outputImageDirection = new DIRECTION[outputImageGauss.GetLength(0) - (sobelDim - 1), outputImageGauss.GetLength(1) - (sobelDim - 1)]; for (int y = sobelDim / 2; y < outputImageGauss.GetLength(0) - sobelDim / 2; y++) { for (int x = sobelDim / 2; x < outputImageGauss.GetLength(1) - sobelDim / 2; x++) { float resx = applyConv(x, y, outputImageGauss, convMatrixGx); float resy = applyConv(x, y, outputImageGauss, convMatrixGy); double r = Math.Sqrt((resx * resx) + (resy * resy)); /*if (r < 0) r = 0; * if (r > 255) r = 255;*/ outputImageSobel[y - sobelDim / 2, x - sobelDim / 2] = (float)r; outputImageDirection[y - sobelDim / 2, x - sobelDim / 2] = radiansToDirection(Math.Atan2(resy, resx)); } } /////////////////////////////////// output image Sobel & direction -> non maximum suppression -> outputImageNMS float float[,] floatOutputImageNms = new float[outputImageSobel.GetLength(0), outputImageSobel.GetLength(1)]; for (int y = 0; y < outputImageSobel.GetLength(0); y++) { for (int x = 0; x < outputImageSobel.GetLength(1); x++) { switch (outputImageDirection[y, x]) { case DIRECTION.HORIZONTAL: if (x >= 1 && x < outputImageSobel.GetLength(1) - 1 && outputImageSobel[y, x] > outputImageSobel[y, x - 1] && outputImageSobel[y, x] >= outputImageSobel[y, x + 1]) { floatOutputImageNms[y, x] = outputImageSobel[y, x]; } break; case DIRECTION.LEFT45: //case DIRECTION.RIGHT45: if (x >= 1 && x < outputImageSobel.GetLength(1) - 1 && y >= 1 && y < outputImageSobel.GetLength(0) - 1 && outputImageSobel[y, x] >= outputImageSobel[y - 1, x + 1] && outputImageSobel[y, x] > outputImageSobel[y + 1, x - 1]) { floatOutputImageNms[y, x] = outputImageSobel[y, x]; } break; case DIRECTION.VERTICAL: if (y >= 1 && y < outputImageSobel.GetLength(0) - 1 && outputImageSobel[y, x] > outputImageSobel[y - 1, x] && outputImageSobel[y, x] >= outputImageSobel[y + 1, x]) { floatOutputImageNms[y, x] = outputImageSobel[y, x]; } break; //case DIRECTION.LEFT45: case DIRECTION.RIGHT45: if (x >= 1 && x < outputImageSobel.GetLength(1) - 1 && y >= 1 && y < outputImageSobel.GetLength(0) - 1 && outputImageSobel[y, x] > outputImageSobel[y - 1, x - 1] && outputImageSobel[y, x] >= outputImageSobel[y + 1, x + 1]) { floatOutputImageNms[y, x] = outputImageSobel[y, x]; } break; } } } /////////////////////////////////// output image non maximum suppression float -> acceptance matrix & byte outputNms bool[,] acceptanceMatrix = new bool[floatOutputImageNms.GetLength(0), floatOutputImageNms.GetLength(1)]; byte[,] outputImageNms = new byte[floatOutputImageNms.GetLength(0), floatOutputImageNms.GetLength(1)]; for (int y = 0; y < floatOutputImageNms.GetLength(0); y++) { for (int x = 0; x < floatOutputImageNms.GetLength(1); x++) { float r = floatOutputImageNms[y, x]; if (r > 255) { r = 255; } if (r < 0) { r = 0; } outputImageNms[y, x] = (byte)r; acceptanceMatrix[y, x] = outputImageNms[y, x] >= highThreshold; } } Queue <KeyValuePair <int, int> > neighbors = new Queue <KeyValuePair <int, int> >(); for (int y = 0; y < outputImageNms.GetLength(0); y++) { for (int x = 0; x < outputImageNms.GetLength(1); x++) { if (acceptanceMatrix[y, x]) { if (y >= 1 && outputImageNms[y - 1, x] >= lowThreshold && outputImageNms[y - 1, x] < highThreshold) // up { neighbors.Enqueue(new KeyValuePair <int, int>(y - 1, x)); } if (y < outputImageNms.GetLength(0) - 1 && outputImageNms[y + 1, x] >= lowThreshold && outputImageNms[y + 1, x] < highThreshold) // down { neighbors.Enqueue(new KeyValuePair <int, int>(y + 1, x)); } if (x < outputImageNms.GetLength(1) - 1 && outputImageNms[y, x + 1] >= lowThreshold && outputImageNms[y, x + 1] < highThreshold) // right { neighbors.Enqueue(new KeyValuePair <int, int>(y, x + 1)); } if (x >= 1 && outputImageNms[y, x - 1] >= lowThreshold && outputImageNms[y, x - 1] < highThreshold) // left { neighbors.Enqueue(new KeyValuePair <int, int>(y, x - 1)); } if (y >= 1 && x < outputImageNms.GetLength(1) - 1 && outputImageNms[y - 1, x + 1] >= lowThreshold && outputImageNms[y - 1, x + 1] < highThreshold) //right-up { neighbors.Enqueue(new KeyValuePair <int, int>(y - 1, x + 1)); } if (x >= 1 && y >= 1 && outputImageNms[y - 1, x - 1] >= lowThreshold && outputImageNms[y - 1, x - 1] < highThreshold) // left-up { neighbors.Enqueue(new KeyValuePair <int, int>(y - 1, x - 1)); } if (y < outputImageNms.GetLength(0) - 1 && x >= 1 && outputImageNms[y + 1, x - 1] >= lowThreshold && outputImageNms[y + 1, x - 1] < highThreshold) // left-down { neighbors.Enqueue(new KeyValuePair <int, int>(y + 1, x - 1)); } if (x < outputImageNms.GetLength(1) - 1 && y < outputImageNms.GetLength(0) - 1 && outputImageNms[y + 1, x + 1] >= lowThreshold && outputImageNms[y + 1, x + 1] < highThreshold) // right-down { neighbors.Enqueue(new KeyValuePair <int, int>(y + 1, x + 1)); } } } } while (neighbors.Count > 0) { KeyValuePair <int, int> xy = neighbors.Dequeue(); int y = xy.Key; int x = xy.Value; if (!acceptanceMatrix[y, x]) { acceptanceMatrix[y, x] = true; if (y >= 1 && outputImageNms[y - 1, x] >= lowThreshold && outputImageNms[y - 1, x] < highThreshold) // up { neighbors.Enqueue(new KeyValuePair <int, int>(y - 1, x)); } if (y < outputImageNms.GetLength(0) - 1 && outputImageNms[y + 1, x] >= lowThreshold && outputImageNms[y + 1, x] < highThreshold) // down { neighbors.Enqueue(new KeyValuePair <int, int>(y + 1, x)); } if (x < outputImageNms.GetLength(1) - 1 && outputImageNms[y, x + 1] >= lowThreshold && outputImageNms[y, x + 1] < highThreshold) // right { neighbors.Enqueue(new KeyValuePair <int, int>(y, x + 1)); } if (x >= 1 && outputImageNms[y, x - 1] >= lowThreshold && outputImageNms[y, x - 1] < highThreshold) // left { neighbors.Enqueue(new KeyValuePair <int, int>(y, x - 1)); } if (y >= 1 && x < outputImageNms.GetLength(1) - 1 && outputImageNms[y - 1, x + 1] >= lowThreshold && outputImageNms[y - 1, x + 1] < highThreshold) //right-up { neighbors.Enqueue(new KeyValuePair <int, int>(y - 1, x + 1)); } if (x >= 1 && y >= 1 && outputImageNms[y - 1, x - 1] >= lowThreshold && outputImageNms[y - 1, x - 1] < highThreshold) // left-up { neighbors.Enqueue(new KeyValuePair <int, int>(y - 1, x - 1)); } if (y < outputImageNms.GetLength(0) - 1 && x >= 1 && outputImageNms[y + 1, x - 1] >= lowThreshold && outputImageNms[y + 1, x - 1] < highThreshold) // left-down { neighbors.Enqueue(new KeyValuePair <int, int>(y + 1, x - 1)); } if (x < outputImageNms.GetLength(1) - 1 && y < outputImageNms.GetLength(0) - 1 && outputImageNms[y + 1, x + 1] >= lowThreshold && outputImageNms[y + 1, x + 1] < highThreshold) // right-down { neighbors.Enqueue(new KeyValuePair <int, int>(y + 1, x + 1)); } } } /////////////////////////////////// output image non maximum suppression -> histeresis threshold-> outputImageHisteresis float[,] outputImageHist = new float[outputImageNms.GetLength(0), outputImageNms.GetLength(1)]; for (int y = 0; y < outputImageNms.GetLength(0); y++) { for (int x = 0; x < outputImageNms.GetLength(1); x++) { if (acceptanceMatrix[y, x]) { outputImageHist[y, x] = outputImageNms[y, x]; } } } ////////////////////////////////// to byte byte[,] outputGray = new byte[outputImageHist.GetLength(0), outputImageHist.GetLength(1)]; for (int y = 0; y < outputGray.GetLength(0); y++) { for (int x = 0; x < outputGray.GetLength(1); x++) { float r = outputImageHist[y, x]; if (r < 0) { r = 0; } if (r > 255) { r = 255; } outputGray[y, x] = (byte)r; } } outputImage.setSizeX(outputGray.GetLength(1)); outputImage.setSizeY(outputGray.GetLength(0)); outputImage.setGray(outputGray); return(outputImage); }
public void Execute() { ProcessedImage = new SKBitmap(ProcessingImage.Width, ProcessingImage.Height); int sigma = 1; double constant = 1d / (2 * Math.PI * sigma * sigma); for (int y = sigma; y < ProcessingImage.Height - sigma; y++) { for (int x = sigma; x < ProcessingImage.Width - sigma; x++) { double suma = 0, distanta = 0, sumBeforeDivide = 0; for (int i = -sigma; i <= sigma; i++) { for (int j = -sigma; j <= sigma; j++) { distanta = ((i * i) + (j * j)) / (2 * sigma * sigma); sumBeforeDivide = sumBeforeDivide + ProcessingImage.GetPixel(x + i, y + i).Red *(constant * Math.Exp(-distanta)); suma = suma + constant * Math.Exp(-distanta); } } for (int i = -sigma; i <= sigma; i++) { for (int j = -sigma; j <= sigma; j++) { byte value = (byte)(sumBeforeDivide / suma); ProcessedImage.SetPixel(x, y, new SKColor(value, value, value)); } } } } for (int y = 0; y < sigma; y++) { for (int x = 0; x < ProcessingImage.Width; x++) { ProcessedImage.SetPixel(x, y, ProcessingImage.GetPixel(x, y)); ProcessedImage.SetPixel(ProcessingImage.Width - x - 1, y, ProcessingImage.GetPixel(ProcessingImage.Width - x - 1, y)); } } for (int y = ProcessingImage.Height - sigma; y < ProcessingImage.Height; y++) { for (int x = 0; x < ProcessingImage.Width; x++) { ProcessedImage.SetPixel(x, y, ProcessingImage.GetPixel(x, y)); ProcessedImage.SetPixel(ProcessingImage.Width - x - 1, y, ProcessingImage.GetPixel(ProcessingImage.Width - x - 1, y)); } } for (int y = 0; y < ProcessingImage.Height; y++) { for (int x = 0; x < sigma; x++) { ProcessedImage.SetPixel(x, y, ProcessingImage.GetPixel(x, y)); ProcessedImage.SetPixel(ProcessingImage.Width - x - 1, y, ProcessingImage.GetPixel(ProcessingImage.Width - x - 1, y)); } } for (int y = 0; y < ProcessingImage.Height; y++) { for (int x = ProcessingImage.Width - sigma; x < ProcessingImage.Width; x++) { ProcessedImage.SetPixel(x, y, ProcessingImage.GetPixel(x, y)); ProcessedImage.SetPixel(ProcessingImage.Width - x - 1, y, ProcessingImage.GetPixel(ProcessingImage.Width - x - 1, y)); } } }
public ProcessingImage filter(ProcessingImage inputImage) { ProcessingImage outputImage = new ProcessingImage(); outputImage.copyAttributesAndAlpha(inputImage); outputImage.addWatermark("blur watermark: media aritmetica in cruce (sus, jo, centru, stanga, dreapta)"); if (inputImage.grayscale) { byte[,] outputGray = new byte[inputImage.getSizeY(), inputImage.getSizeX()]; byte[,] inputGray = inputImage.getGray(); for (int y = 1; y < inputImage.getSizeY() - 1; y++) { for (int x = 1; x < inputImage.getSizeX() - 1; x++) { outputGray[y, x] = (byte)(( inputGray[y - 1, x] + +inputGray[y, x - 1] + inputGray[y, x] * 0 + inputGray[y, x + 1] + inputGray[y + 1, x] ) / 5); } } outputImage.setGray(outputGray); } else { byte[,] outputRed = new byte[inputImage.getSizeY(), inputImage.getSizeX()]; byte[,] outputGreen = new byte[inputImage.getSizeY(), inputImage.getSizeX()]; byte[,] outputBlue = new byte[inputImage.getSizeY(), inputImage.getSizeX()]; byte[,] inputRed = inputImage.getRed(); byte[,] inputGreen = inputImage.getGreen(); byte[,] inputBlue = inputImage.getBlue(); for (int y = 1; y < inputImage.getSizeY() - 1; y++) { for (int x = 1; x < inputImage.getSizeX() - 1; x++) { outputRed[y, x] = (byte)(( inputRed[y - 1, x] + +inputRed[y, x - 1] + inputRed[y, x] * 0 + inputRed[y, x + 1] + inputRed[y + 1, x] ) / 5); outputGreen[y, x] = (byte)(( inputGreen[y - 1, x] + +inputGreen[y, x - 1] + inputGreen[y, x] * 0 + inputGreen[y, x + 1] + inputGreen[y + 1, x] ) / 5); outputBlue[y, x] = (byte)(( inputBlue[y - 1, x] + +inputBlue[y, x - 1] + inputBlue[y, x] * 0 + inputBlue[y, x + 1] + inputBlue[y + 1, x] ) / 5); } } outputImage.setRed(outputRed); outputImage.setGreen(outputGreen); outputImage.setBlue(outputBlue); } return(outputImage); }
public ProcessingImage filter(ProcessingImage inputImage) { ProcessingImage outputImage = new ProcessingImage(); outputImage.copyAttributesAndAlpha(inputImage); outputImage.addWatermark(String.Format("LoG watermark")); // intout -> laplacian of gaussian -> output LOG const int logDim = 5; float[,] laplacianOfGaussian = new float[logDim, logDim] { { 0, 0, -1, 0, 0 }, { 0, -1, -2, -1, 0 }, { -1, -2, 16, -2, -1 }, { 0, -1, -2, -1, 0 }, { 0, 0, -1, 0, 0 }, }; byte[,] inputLuminance = inputImage.getLuminance(); int[,] outputImageLoG = new int[inputImage.getSizeY() - (logDim - 1), inputImage.getSizeX() - (logDim - 1)]; for (int y = logDim / 2; y < inputImage.getSizeY() - logDim / 2; y++) //getlength0 { for (int x = logDim / 2; x < inputImage.getSizeX() - logDim / 2; x++) //getlength1 { float r = applyConv(x, y, inputLuminance, laplacianOfGaussian); outputImageLoG[y - logDim / 2, x - logDim / 2] = (int)r; } } // LOG -> zero crossing -> output byte[,] outputImageZC = new byte[outputImageLoG.GetLength(0), outputImageLoG.GetLength(1)]; for (int y = 0; y < outputImageLoG.GetLength(0); y++) { for (int x = 0; x < outputImageLoG.GetLength(1); x++) { bool zeroCrossing = false; //left if (x >= 1 && Math.Sign(outputImageLoG[y, x]) != Math.Sign(outputImageLoG[y, x - 1])) { zeroCrossing = true; } //upper left else if (x >= 1 && y >= 1 && Math.Sign(outputImageLoG[y, x]) != Math.Sign(outputImageLoG[y - 1, x - 1])) { zeroCrossing = true; } //up else if (y >= 1 && Math.Sign(outputImageLoG[y, x]) != Math.Sign(outputImageLoG[y - 1, x])) { zeroCrossing = true; } //upper right else if (y >= 1 && x < outputImageLoG.GetLength(1) - 1 && Math.Sign(outputImageLoG[y, x]) != Math.Sign(outputImageLoG[y - 1, x + 1])) { zeroCrossing = true; } if (zeroCrossing) { outputImageZC[y, x] = 255; } } } ////////////////////////////////// to byte byte[,] outputGray = new byte[outputImageZC.GetLength(0), outputImageZC.GetLength(1)]; for (int y = 0; y < outputGray.GetLength(0); y++) { for (int x = 0; x < outputGray.GetLength(1); x++) { float r = outputImageZC[y, x]; if (r < 0) { r = 0; } if (r > 255) { r = 255; } outputGray[y, x] = (byte)r; } } outputImage.setSizeX(outputGray.GetLength(1)); outputImage.setSizeY(outputGray.GetLength(0)); outputImage.setGray(outputGray); return(outputImage); }
public AuthenticDocModel(SignalProcess _process, IThreadingCrossPlatform _IThreading, IDevice _currentDevice, IMediaPicker _mediaPicker, IImageSupport _imageSupport, IFileSupport _fileSupport, string[] _testURls) { m_IThreading = _IThreading; m_IFileSupport = _fileSupport; m_IImageSupport = _imageSupport; m_testURls = _testURls; SetupMedia(_currentDevice, _mediaPicker); buttonCameraName = "Camera"; //urlEntryText = directory; TakePictureFromCameraCommand = new RelayCommand(TakePictureFromCameraRelay, param => this.canExecute); LoadImageFromFileCommand = new RelayCommand(LoadImageFromFileCommandRelay, param => this.canExecute); LoadImageFromURLCommand = new RelayCommand(LoadImageFromURLCommandRelay, param => this.canExecute); TestButtonCommand = new RelayCommand(TestButtonCommandRelay, param => this.canExecute); ProcessCommand = new RelayCommand(ProcessCommandRelay, param => this.CanExecuteProcess); URLEntryPickerChangedCommand = new RelayCommand(urlEntryPickerChangedCommandRelay, param => this.canExecute); updateImageEvent += new EventHandler <ImageSource>((o, s) => { imageSource = s; }); imageSource = new UriImageSource { Uri = new Uri("https://grandprix20.files.wordpress.com/2012/11/317757_423537204379996_1874288384_n-1.png"), CachingEnabled = false }; processImage = new ProcessingImage(_process); }