public override byte[] ResampleImage(RlViewer.Files.LocatorFile file, System.Drawing.Rectangle area) { float[] image = new float[area.Width * area.Height]; float[] imageArea = file.GetArea(area).ToArea<float>(file.Header.BytesPerSample); int toInclusiveX = area.Location.X + area.Width; toInclusiveX = toInclusiveX > file.Width ? file.Width : toInclusiveX; int toInclusiveY = area.Location.Y + area.Height; toInclusiveY = toInclusiveY > file.Height ? file.Height : toInclusiveY; int counter = 0; //Parallel.For(area.Location.X, toInclusiveX, (i, loopState) => //{ for (int i = area.Location.X; i < toInclusiveX; i++) { for (int j = area.Location.Y; j < toInclusiveY; j++) { var oldAmplVal = imageArea[(j - area.Location.Y) * area.Width + (i - area.Location.X)]; var newAmplVal = GetPlaneValue(i / Selector.RangeCompressionCoef, j / Selector.AzimuthCompressionCoef, PointToPlane(new System.Drawing.Point(i / Selector.RangeCompressionCoef, j / Selector.AzimuthCompressionCoef), AmplitudeSolution)); var newRcsVal = GetPlaneValue(i / Selector.RangeCompressionCoef, j / Selector.AzimuthCompressionCoef, PointToPlane(new System.Drawing.Point(i / Selector.RangeCompressionCoef, j / Selector.AzimuthCompressionCoef), RcsSolution)); var diff = oldAmplVal / newAmplVal * newRcsVal; diff = diff < 0 ? 0 : diff; image[(j - area.Location.Y) * area.Width + (i - area.Location.X)] = diff; } System.Threading.Interlocked.Increment(ref counter); OnProgressReport((int)(counter / Math.Ceiling((double)(toInclusiveX - area.Location.X)) * 100)); if (OnCancelWorker()) { break; // loopState.Break(); } } //}); if (Cancelled) { return null; } byte[] imageB = new byte[image.Length * 4]; Buffer.BlockCopy(image, 0, imageB, 0, imageB.Length); return imageB; }
public override byte[] ResampleImage(RlViewer.Files.LocatorFile file, System.Drawing.Rectangle area) { float[] image = new float[area.Width * area.Height]; int toInclusiveX = area.Location.X + area.Width; toInclusiveX = toInclusiveX > file.Width ? file.Width : toInclusiveX; int toInclusiveY = area.Location.Y + area.Height; toInclusiveY = toInclusiveY > file.Height ? file.Height : toInclusiveY; int counter = 0; float[] imageArea = file.GetArea(area).ToArea<float>(file.Header.BytesPerSample); Parallel.For(area.Location.X, toInclusiveX, (i, loopState) => { var zValues = _zCoefficients.Select(x => Extrapolate(i, x)).ToArray(); var yValues = _yCoefficients.Select(x => Extrapolate(i, x)).ToArray(); var _zCoefs = LinearEquation.SolveEquation(yValues, zValues); for (int j = area.Location.Y; j < toInclusiveY; j++) { var oldVal = imageArea[(j - area.Location.Y) * area.Width + (i - area.Location.X)]; var newAmplVal = Extrapolate(j, _zCoefs); var rcsVal = RcsProvider.GetValueAt(oldVal); var diff = oldVal / newAmplVal * rcsVal; diff = diff < 0 ? 0 : diff; image[(j - area.Location.Y) * area.Width + (i - area.Location.X)] = diff; } System.Threading.Interlocked.Increment(ref counter); OnProgressReport((int)(counter / Math.Ceiling((double)(toInclusiveX - area.Location.X)) * 100)); if (OnCancelWorker()) { loopState.Break(); } }); if (Cancelled) { return null; } byte[] imageB = new byte[image.Length * 4]; Buffer.BlockCopy(image, 0, imageB, 0, imageB.Length); return imageB; }