public ScalingFactor(int colid, ScalingMethod method, VBuffer <float> mean, VBuffer <float> scale) { scalingMethod = method; columnId = colid; this.mean = mean; this.scale = scale; }
protected override void Context() { base.Context(); _newScalingMethod = A.Fake <ScalingMethod>(); _parameterScaling = A.Fake <ParameterScaling>(); _parameterScalingDTO = new ParameterScalingDTO(_parameterScaling); A.CallTo(() => _parameterScaling.TargetScaledValueInDisplayUnit).Returns(40); }
protected override void Context() { _targetParameter = A.Fake <IParameter>(); _sourceParameter = A.Fake <IParameter>(); _scalingMethod = A.Fake <ScalingMethod>(); sut = new ParameterScaling(_sourceParameter, _targetParameter); sut.ScalingMethod = _scalingMethod; }
protected override void Context() { _targetParameter = A.Fake <IParameter>(); _sourceParameter = A.Fake <IParameter>(); _scaledValue = 20; _scalingMethod = A.Fake <ScalingMethod>(); sut = new ParameterScaling(_sourceParameter, _targetParameter); sut.ScalingMethod = _scalingMethod; A.CallTo(() => _scalingMethod.ScaledValueFor(sut)).Returns(_scaledValue); }
protected override void Context() { _command = A.Fake <IPKSimCommand>(); _targetParameter = A.Fake <IParameter>(); _sourceParameter = A.Fake <IParameter>(); _scalingMethod = A.Fake <ScalingMethod>(); sut = new ParameterScaling(_sourceParameter, _targetParameter); sut.ScalingMethod = _scalingMethod; A.CallTo(() => _scalingMethod.Scale(sut)).Returns(_command); }
protected override void Context() { _targetParameter = A.Fake <IParameter>(); _sourceParameter = A.Fake <IParameter>(); _scaledValueInGuiUnit = 30; _scalingMethod = A.Fake <ScalingMethod>(); sut = new ParameterScaling(_sourceParameter, _targetParameter); _targetParameter.ValueInDisplayUnit = _scaledValueInGuiUnit; sut.ScalingMethod = _scalingMethod; }
protected override void Context() { _targetParameter = DomainHelperForSpecs.ConstantParameterWithValue(10); _sourceParameter = DomainHelperForSpecs.ConstantParameterWithValue(20); _targetParameter.ValueInDisplayUnit = 30; _scalingMethod = A.Fake <ScalingMethod>(); sut = new ParameterScaling(_sourceParameter, _targetParameter) { ScalingMethod = _scalingMethod }; }
public ScalingFactor(IHost host, int colid, ScalerStrategy strategy, List <ColumnStatObs> obs) { columnId = colid; switch (strategy) { case ScalerStrategy.meanVar: scalingMethod = ComputeMeanVar(host, obs, out mean, out scale); break; case ScalerStrategy.minMax: scalingMethod = ComputeMinMax(host, obs, out mean, out scale); break; default: throw host.ExceptNotSupp($"Unknown scaling strategy {strategy}."); } }
protected override void Context() { _scalingMethodSpecOK1 = A.Fake <IScalingMethodSpecification>(); _scalingMethodSpecNotOK1 = A.Fake <IScalingMethodSpecification>(); _scalingMethodSpecOK2 = A.Fake <IScalingMethodSpecification>(); _repository = A.Fake <IRepository <IScalingMethodSpecification> >(); _parameterScaling = A.Fake <ParameterScaling>(); _scalingMethod1 = A.Fake <ScalingMethod>(); _scalingMethod2 = A.Fake <ScalingMethod>(); A.CallTo(() => _scalingMethodSpecOK1.IsSatisfiedBy(_parameterScaling)).Returns(true); A.CallTo(() => _scalingMethodSpecOK2.IsSatisfiedBy(_parameterScaling)).Returns(true); A.CallTo(() => _scalingMethodSpecNotOK1.IsSatisfiedBy(_parameterScaling)).Returns(false); A.CallTo(() => _scalingMethodSpecOK1.Method).Returns(_scalingMethod1); A.CallTo(() => _scalingMethodSpecOK2.Method).Returns(_scalingMethod2); A.CallTo(() => _repository.All()).Returns(new[] { _scalingMethodSpecOK1, _scalingMethodSpecOK2, _scalingMethodSpecNotOK1 }); sut = new ScalingMethodTask(_repository); }
public Bitmap ApplyFilter(Bitmap originalImage, int[,] mask, ScalingMethod scalingMethod = ScalingMethod.Cutting, EdgeProcessingMethod edgeProcessingMethod = EdgeProcessingMethod.UseExistingPixels) { if (originalImage.PixelFormat != PixelFormat.Format8bppIndexed) { throw new NotSupportedException("Only 8bppIndexed bitmap are supported"); } switch (edgeProcessingMethod) { case EdgeProcessingMethod.DuplicateEdges: return(ApplyMaskDuplicatingEdges(originalImage, mask, scalingMethod)); case EdgeProcessingMethod.IgnoreEdges: return(ApplyMaskIgnoringEdges(originalImage, mask, scalingMethod)); case EdgeProcessingMethod.UseExistingPixels: return(ApplyMaskUsingExistingNeighbourhood(originalImage, mask, scalingMethod)); default: throw new ArgumentException("Unknown edge processing method"); } }
protected override void Context() { base.Context(); _newValueInGuiUnit = 145; _targetParameterDTO = A.Fake <ParameterDTO>(); _sourceParameterDTO = A.Fake <ParameterDTO>(); _parameterScaling = A.Fake <ParameterScaling>(); _sourceParameter = A.Fake <IParameter>(); _targetParameter = A.Fake <IParameter>(); A.CallTo(() => _targetParameterDTO.Value).Returns(5); A.CallTo(() => _sourceParameterDTO.Value).Returns(6); _displayFullPath = "tralalal"; _scalingMethod = A.Fake <ScalingMethod>(); A.CallTo(() => _parameterScaling.SourceParameter).Returns(_sourceParameter); A.CallTo(() => _parameterScaling.TargetParameter).Returns(_targetParameter); A.CallTo(() => _parameterDTOMapper.MapFrom(_sourceParameter)).Returns(_sourceParameterDTO); A.CallTo(() => _parameterDTOMapper.MapFrom(_targetParameter)).Returns(_targetParameterDTO); _parameterScaling.ScalingMethod = _scalingMethod; A.CallTo(_fullPathDisplayResolver).WithReturnType <string>().Returns(_displayFullPath); A.CallTo(() => _parameterScaling.TargetScaledValueInDisplayUnit).Returns(_newValueInGuiUnit); A.CallTo(() => _parameterScaling.SourceValueInDisplayUnit).Returns(_sourceParameterDTO.Value); A.CallTo(() => _parameterScaling.TargetDefaultValueInDisplayUnit).Returns(_targetParameterDTO.Value); }
public Bitmap ApplyFilter(Bitmap originalImage, int[,] maskX, int[,] maskY, ScalingMethod scalingMethod = ScalingMethod.Cutting, EdgeProcessingMethod edgeProcessingMethod = EdgeProcessingMethod.UseExistingPixels) { if (originalImage.PixelFormat != PixelFormat.Format8bppIndexed) { throw new NotSupportedException("Only 8bppIndexed bitmap are supported"); } int[,] xResult; int[,] yResult; switch (edgeProcessingMethod) { case EdgeProcessingMethod.DuplicateEdges: xResult = ApplyMaskDuplicatingEdges(originalImage, maskX); yResult = ApplyMaskDuplicatingEdges(originalImage, maskY); break; case EdgeProcessingMethod.IgnoreEdges: xResult = ApplyMaskIgnoringEdges(originalImage, maskX); yResult = ApplyMaskIgnoringEdges(originalImage, maskY); break; case EdgeProcessingMethod.UseExistingPixels: xResult = ApplyMaskUsingExistingNeighbourhood(originalImage, maskX); yResult = ApplyMaskUsingExistingNeighbourhood(originalImage, maskY); break; default: throw new ArgumentException("Unknown edge processing method"); } int width = xResult.GetLength(1); int height = xResult.GetLength(0); int[,] gradient = new int[height, width]; for (int i = 0; i < height; ++i) { for (int j = 0; j < width; ++j) { gradient[i, j] = Math.Abs(xResult[i, j]) + Math.Abs(yResult[i, j]); } } byte[,] rescaled; switch (scalingMethod) { case ScalingMethod.RangeRescale: rescaled = RescaleStretch(gradient); break; case ScalingMethod.Cutting: rescaled = RescaleCut(gradient); break; case ScalingMethod.Trivalent: rescaled = RescaleTrivalent(gradient); break; default: throw new ArgumentException("Unknown rescaling method"); } Bitmap finalImage = new Bitmap(width, height, originalImage.PixelFormat); ColorPalette finalPalette = finalImage.Palette; for (int i = 0; i < 256; ++i) { finalPalette.Entries[i] = Color.FromArgb(i, i, i); } finalImage.Palette = finalPalette; BitmapData finalBitmapData = finalImage.LockBits( new Rectangle(0, 0, finalImage.Width, finalImage.Height), ImageLockMode.ReadOnly, finalImage.PixelFormat); byte *finalBitmapPointer = (byte *)finalBitmapData.Scan0.ToPointer(); byte finalBitmapRemain = (byte)(finalBitmapData.Stride - finalBitmapData.Width); for (int i = 0; i < height; ++i) { for (int j = 0; j < width; ++j) { finalBitmapPointer[0] = rescaled[i, j]; ++finalBitmapPointer; } finalBitmapPointer += finalBitmapRemain; } finalImage.UnlockBits(finalBitmapData); return(finalImage); }
public virtual IScaling Get(ScalingMethod model) => _factory.Get(model);
public IScaling Get(ScalingMethod scaling) => scaling switch {
public void ScalingMethodChanged(ParameterScalingDTO parameterScalingDTO, ScalingMethod newScalingMethod) { parameterScalingDTO.ScalingMethod = newScalingMethod; ScalingPerformed = false; }
private void cutRadioButton_CheckedChanged(object sender, EventArgs e) { scalingMethod = ScalingMethod.Cutting; }
private void trivalentRadioButton_CheckedChanged(object sender, EventArgs e) { scalingMethod = ScalingMethod.Trivalent; }
private void rescaleRangeRadioButton_CheckedChanged(object sender, EventArgs e) { scalingMethod = ScalingMethod.RangeRescale; }
protected override void Because() { _result = sut.DefaultMethodFor(_parameterScaling); }
private unsafe Bitmap ApplyMaskDuplicatingEdges(Bitmap originalImage, int[,] mask, ScalingMethod scalingMethod) { int depth = 1; int maskHeight = mask.GetLength(0); int maskWidth = mask.GetLength(1); Bitmap finalImage = new Bitmap( originalImage.Width, originalImage.Height, originalImage.PixelFormat); Bitmap unwrappedImage = new Bitmap( originalImage.Width + (maskWidth - 1), originalImage.Height + (maskHeight - 1), originalImage.PixelFormat); if (depth == 1) { ColorPalette finalPalette = finalImage.Palette; for (int i = 0; i < 256; ++i) { finalPalette.Entries[i] = Color.FromArgb(i, i, i); } finalImage.Palette = finalPalette; unwrappedImage.Palette = finalPalette; } lock (imageLock) { BitmapData originalBitmapData = originalImage.LockBits( new Rectangle(0, 0, originalImage.Width, originalImage.Height), ImageLockMode.ReadOnly, originalImage.PixelFormat); BitmapData unwrappedBitmapData = unwrappedImage.LockBits( new Rectangle(0, 0, unwrappedImage.Width, unwrappedImage.Height), ImageLockMode.ReadOnly, unwrappedImage.PixelFormat); byte *originalBitmapPointer = (byte *)originalBitmapData.Scan0.ToPointer(); byte *unwrappedBitmapPointer = (byte *)unwrappedBitmapData.Scan0.ToPointer(); byte originalBitmapRemain = (byte)(originalBitmapData.Stride - originalBitmapData.Width); byte unwrappedBitmapRemain = (byte)(unwrappedBitmapData.Stride - unwrappedBitmapData.Width); unwrappedBitmapPointer += unwrappedBitmapData.Stride * (maskHeight / 2) + depth * (maskWidth / 2); int unwrappedPointerOffset = unwrappedBitmapRemain + maskWidth * depth - depth; int workspaceWidth = originalBitmapData.Width; int workspaceHeight = originalBitmapData.Height; //initial copying for (int i = 0; i < workspaceHeight; ++i) { for (int j = 0; j < workspaceWidth; ++j) { unwrappedBitmapPointer[0] = originalBitmapPointer[0]; originalBitmapPointer += depth; unwrappedBitmapPointer += depth; } originalBitmapPointer += originalBitmapRemain; unwrappedBitmapPointer += unwrappedPointerOffset; } unwrappedBitmapPointer = (byte *)unwrappedBitmapData.Scan0.ToPointer() + (maskWidth / 2) * depth; originalBitmapPointer = (byte *)originalBitmapData.Scan0.ToPointer(); //copy rows for (int i = 0; i < maskHeight / 2; ++i) { for (int j = 0; j < workspaceWidth; ++j) { unwrappedBitmapPointer[0] = originalBitmapPointer[0]; originalBitmapPointer += depth; unwrappedBitmapPointer += depth; } originalBitmapPointer -= originalBitmapData.Width; unwrappedBitmapPointer += unwrappedPointerOffset; } unwrappedBitmapPointer += unwrappedBitmapData.Stride * originalBitmapData.Height; originalBitmapPointer += originalBitmapData.Stride * originalBitmapData.Height; originalBitmapPointer -= originalBitmapData.Width; for (int i = 0; i < maskHeight / 2; ++i) { for (int j = 0; j < workspaceWidth; ++j) { unwrappedBitmapPointer[0] = originalBitmapPointer[0]; originalBitmapPointer += depth; unwrappedBitmapPointer += depth; } originalBitmapPointer -= originalBitmapData.Width; unwrappedBitmapPointer += unwrappedPointerOffset; } workspaceHeight = unwrappedBitmapData.Height; unwrappedBitmapPointer = (byte *)unwrappedBitmapData.Scan0.ToPointer(); originalBitmapPointer = unwrappedBitmapPointer; //Copy columns for (int i = 0; i < workspaceHeight; ++i) { originalBitmapPointer += (maskHeight / 2) * depth; for (int j = 0; j < maskWidth / 2; ++j) { unwrappedBitmapPointer[0] = originalBitmapPointer[0]; unwrappedBitmapPointer += depth; } originalBitmapPointer += originalBitmapData.Width * depth - depth; unwrappedBitmapPointer += originalBitmapData.Width * depth; for (int j = 0; j < maskWidth / 2; ++j) { unwrappedBitmapPointer[0] = originalBitmapPointer[0]; unwrappedBitmapPointer += depth; } originalBitmapPointer += maskWidth / 2 + unwrappedBitmapRemain + depth; unwrappedBitmapPointer += unwrappedBitmapRemain; } originalImage.UnlockBits(originalBitmapData); BitmapData finalBitmapData = finalImage.LockBits( new Rectangle(0, 0, finalImage.Width, finalImage.Height), ImageLockMode.ReadOnly, finalImage.PixelFormat); byte *finalBitmapPointer = (byte *)finalBitmapData.Scan0.ToPointer(); byte finalBitmapRemain = (byte)(finalBitmapData.Stride - finalBitmapData.Width); unwrappedBitmapPointer = (byte *)unwrappedBitmapData.Scan0.ToPointer(); unwrappedBitmapPointer += unwrappedBitmapData.Stride * (maskHeight / 2) + depth * (maskWidth / 2); int helpingPointerOffset = unwrappedBitmapData.Stride - maskWidth * depth; int helpingPointerStartOffset = unwrappedBitmapData.Stride * (maskHeight / 2) + depth * (maskWidth / 2); workspaceWidth = unwrappedBitmapData.Width - maskWidth + depth; workspaceHeight = unwrappedBitmapData.Height - maskHeight + depth; //set up helping pointer byte *helpingPointer; int[,] result = new int[workspaceHeight, workspaceWidth]; int usedSum; int pixelSum; for (int i = 0; i < workspaceHeight; ++i) { for (int j = 0; j < workspaceWidth; ++j) { helpingPointer = unwrappedBitmapPointer; helpingPointer -= helpingPointerStartOffset; usedSum = 0; pixelSum = 0; for (int k = 0; k < maskHeight; ++k) { for (int l = 0; l < maskWidth; ++l) { pixelSum += mask[k, l] * helpingPointer[0]; usedSum += mask[k, l]; helpingPointer += depth; } helpingPointer += helpingPointerOffset; } result[i, j] = pixelSum / (usedSum == 0 ? 1 : usedSum); unwrappedBitmapPointer += depth; } unwrappedBitmapPointer += unwrappedPointerOffset; } byte[,] rescaled; switch (scalingMethod) { case ScalingMethod.RangeRescale: rescaled = RescaleStretch(result); break; case ScalingMethod.Cutting: rescaled = RescaleCut(result); break; case ScalingMethod.Trivalent: rescaled = RescaleTrivalent(result); break; default: throw new ArgumentException("Unknown rescaling method"); } //apply rescaled pixels for (int i = 0; i < workspaceHeight; ++i) { for (int j = 0; j < workspaceWidth; ++j) { finalBitmapPointer[0] = rescaled[i, j]; finalBitmapPointer += depth; } finalBitmapPointer += finalBitmapRemain; } unwrappedImage.UnlockBits(unwrappedBitmapData); finalImage.UnlockBits(finalBitmapData); } return(finalImage); }
private unsafe Bitmap ApplyMaskIgnoringEdges(Bitmap originalImage, int[,] mask, ScalingMethod scalingMethod) { Bitmap finalImage = new Bitmap( originalImage.Width, originalImage.Height, originalImage.PixelFormat); int depth = 1; int maskHeight = mask.GetLength(0); int maskWidth = mask.GetLength(1); ColorPalette finalPalette = finalImage.Palette; for (int i = 0; i < 256; ++i) { finalPalette.Entries[i] = Color.FromArgb(i, i, i); } finalImage.Palette = finalPalette; lock (imageLock) { BitmapData originalBitmapData = originalImage.LockBits( new Rectangle(0, 0, originalImage.Width, originalImage.Height), ImageLockMode.ReadOnly, originalImage.PixelFormat); BitmapData finalBitmapData = finalImage.LockBits( new Rectangle(0, 0, finalImage.Width, finalImage.Height), ImageLockMode.ReadOnly, finalImage.PixelFormat); byte *originalBitmapPointer = (byte *)originalBitmapData.Scan0.ToPointer(); byte *finalBitmapPointer = (byte *)finalBitmapData.Scan0.ToPointer(); byte originalBitmapRemain = (byte)(originalBitmapData.Stride - originalBitmapData.Width); byte finalBitmapRemain = (byte)(finalBitmapData.Stride - finalBitmapData.Width); //set up pointers starting positions originalBitmapPointer += originalBitmapData.Stride * (maskHeight / 2) + depth * (maskWidth / 2); finalBitmapPointer += finalBitmapData.Stride * (maskHeight / 2) + depth * (maskWidth / 2); //pointers next row offsets int originalPointerOffset = originalBitmapRemain + maskWidth * depth - depth; int finalPointerOffset = finalBitmapRemain + maskWidth * depth - depth; int helpingPointerOffset = originalBitmapData.Stride - maskWidth * depth; int helpingPointerStartOffset = originalBitmapData.Stride * (maskHeight / 2) + depth * (maskWidth / 2); int workspaceWidth = originalImage.Width - maskWidth + depth; int workspaceHeigth = originalImage.Height - maskHeight + depth; //set up helping pointer byte *helpingPointer; int[,] result = new int[workspaceHeigth, workspaceWidth]; int usedSum; int pixelSum; for (int i = 0; i < workspaceHeigth; ++i) { for (int j = 0; j < workspaceWidth; ++j) { helpingPointer = originalBitmapPointer; helpingPointer -= helpingPointerStartOffset; usedSum = 0; pixelSum = 0; for (int k = 0; k < maskHeight; ++k) { for (int l = 0; l < maskWidth; ++l) { pixelSum += mask[k, l] * helpingPointer[0]; usedSum += mask[k, l]; helpingPointer += depth; } helpingPointer += helpingPointerOffset; } result[i, j] = pixelSum / (usedSum == 0 ? 1 : usedSum); originalBitmapPointer += depth; } originalBitmapPointer += originalPointerOffset; } //rescale byte[,] rescaled; switch (scalingMethod) { case ScalingMethod.RangeRescale: rescaled = RescaleStretch(result); break; case ScalingMethod.Cutting: rescaled = RescaleCut(result); break; case ScalingMethod.Trivalent: rescaled = RescaleTrivalent(result); break; default: throw new ArgumentException("Unknown rescaling method"); } //apply rescaled pixels for (int i = 0; i < workspaceHeigth; ++i) { for (int j = 0; j < workspaceWidth; ++j) { finalBitmapPointer[0] = rescaled[i, j]; finalBitmapPointer += depth; } finalBitmapPointer += finalPointerOffset; } originalImage.UnlockBits(originalBitmapData); finalImage.UnlockBits(finalBitmapData); } return(finalImage); }
public Bitmap KirschFilter(Bitmap originalImage, ScalingMethod scalingMethod = ScalingMethod.Cutting, EdgeProcessingMethod edgeProcessingMethod = EdgeProcessingMethod.UseExistingPixels) { if (originalImage.PixelFormat != PixelFormat.Format8bppIndexed) { throw new NotSupportedException("Only 8bppIndexed bitmap are supported"); } int[,] nResult; int[,] neResult; int[,] eResult; int[,] seResult; int[,] sResult; int[,] swResult; int[,] wResult; int[,] nwResult; switch (edgeProcessingMethod) { case EdgeProcessingMethod.DuplicateEdges: nResult = ApplyMaskDuplicatingEdges(originalImage, Mask.KirschN); neResult = ApplyMaskDuplicatingEdges(originalImage, Mask.KirschNE); eResult = ApplyMaskDuplicatingEdges(originalImage, Mask.KirschE); seResult = ApplyMaskDuplicatingEdges(originalImage, Mask.KirschSE); sResult = ApplyMaskDuplicatingEdges(originalImage, Mask.KirschS); swResult = ApplyMaskDuplicatingEdges(originalImage, Mask.KirschSW); wResult = ApplyMaskDuplicatingEdges(originalImage, Mask.KirschW); nwResult = ApplyMaskDuplicatingEdges(originalImage, Mask.KirschNW); break; case EdgeProcessingMethod.IgnoreEdges: nResult = ApplyMaskIgnoringEdges(originalImage, Mask.KirschN); neResult = ApplyMaskIgnoringEdges(originalImage, Mask.KirschNE); eResult = ApplyMaskIgnoringEdges(originalImage, Mask.KirschE); seResult = ApplyMaskIgnoringEdges(originalImage, Mask.KirschSE); sResult = ApplyMaskIgnoringEdges(originalImage, Mask.KirschS); swResult = ApplyMaskIgnoringEdges(originalImage, Mask.KirschSW); wResult = ApplyMaskIgnoringEdges(originalImage, Mask.KirschW); nwResult = ApplyMaskIgnoringEdges(originalImage, Mask.KirschNW); break; case EdgeProcessingMethod.UseExistingPixels: nResult = ApplyMaskUsingExistingNeighbourhood(originalImage, Mask.KirschN); neResult = ApplyMaskUsingExistingNeighbourhood(originalImage, Mask.KirschNE); eResult = ApplyMaskUsingExistingNeighbourhood(originalImage, Mask.KirschE); seResult = ApplyMaskUsingExistingNeighbourhood(originalImage, Mask.KirschSE); sResult = ApplyMaskUsingExistingNeighbourhood(originalImage, Mask.KirschS); swResult = ApplyMaskUsingExistingNeighbourhood(originalImage, Mask.KirschSW); wResult = ApplyMaskUsingExistingNeighbourhood(originalImage, Mask.KirschW); nwResult = ApplyMaskUsingExistingNeighbourhood(originalImage, Mask.KirschNW); break; default: throw new ArgumentException("Unknown edge processing method"); } int width = nResult.GetLength(1); int height = nResult.GetLength(0); int[,] result = new int[height, width]; int[] buf = new int[8]; for (int i = 0; i < height; ++i) { for (int j = 0; j < width; ++j) { buf[0] = nResult[i, j]; buf[1] = neResult[i, j]; buf[2] = eResult[i, j]; buf[3] = seResult[i, j]; buf[4] = eResult[i, j]; buf[5] = swResult[i, j]; buf[6] = wResult[i, j]; buf[7] = nwResult[i, j]; result[i, j] = buf.Max(); } } byte[,] rescaled; switch (scalingMethod) { case ScalingMethod.RangeRescale: rescaled = RescaleStretch(result); break; case ScalingMethod.Cutting: rescaled = RescaleCut(result); break; case ScalingMethod.Trivalent: rescaled = RescaleTrivalent(result); break; default: throw new ArgumentException("Unknown rescaling method"); } Bitmap finalImage = new Bitmap(width, height, originalImage.PixelFormat); ColorPalette finalPalette = finalImage.Palette; for (int i = 0; i < 256; ++i) { finalPalette.Entries[i] = Color.FromArgb(i, i, i); } finalImage.Palette = finalPalette; BitmapData finalBitmapData = finalImage.LockBits( new Rectangle(0, 0, finalImage.Width, finalImage.Height), ImageLockMode.ReadOnly, finalImage.PixelFormat); byte *finalBitmapPointer = (byte *)finalBitmapData.Scan0.ToPointer(); byte finalBitmapRemain = (byte)(finalBitmapData.Stride - finalBitmapData.Width); for (int i = 0; i < height; ++i) { for (int j = 0; j < width; ++j) { finalBitmapPointer[0] = rescaled[i, j]; ++finalBitmapPointer; } finalBitmapPointer += finalBitmapRemain; } finalImage.UnlockBits(finalBitmapData); return(finalImage); }
public static extern int imaqSetSimpleCalibration(IntPtr image, ScalingMethod method, int learnTable, ref GridDescriptor grid, ref CoordinateSystem system);