Skip to content

Commit

Permalink
scancorrelator: Crop-aware Analyze
Browse files Browse the repository at this point in the history
  • Loading branch information
gligli committed Dec 2, 2024
1 parent 42a4a6d commit 8b40f20
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 14 deletions.
Binary file modified VinylScan.exe
Binary file not shown.
2 changes: 1 addition & 1 deletion inputscan.pas
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ implementation

const
CAreaBegin = 0;
CAreaEnd = C45RpmAdapterSize;
CAreaEnd = (C45RpmInnerSize + C45RpmAdapterSize) * 0.5;
CAreaGroovesPerInch = 800;
CRevolutionPointCount = 360;

Expand Down
46 changes: 33 additions & 13 deletions scancorrelator.pas
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ TScanCorrelator = class
function PowellCrop(const x: TVector; obj: Pointer): TScalar;

procedure AngleInit;
procedure Analyze;
procedure Crop;
procedure Analyze;
procedure Rebuild;
public
constructor Create(const AFileNames: TStrings; AOutputDPI: Integer = 2400);
Expand Down Expand Up @@ -243,11 +243,13 @@ procedure TScanCorrelator.GradientsAnalyze(const arg: TVector; var func: Double;
gradResults: TPointDDynArray2;
imgResults: TDoubleDynArray;
mseCoords: array of TPoint;
rLbl: Double;

procedure DoEval(AIndex: PtrInt; AData: Pointer; AItem: TMultiThreadProcItem);
var
i, pos: Integer;
ri, t, r, px, py, cx, cy, rri, skx, sky, sn, cs, p, gimgx, gimgy, gt, gcx, gcy, gskx, gsky: Double;
ct, ri, t, r, px, py, cx, cy, rri, skx, sky, sn, cs, p, gimgx, gimgy, gt, gcx, gcy, gskx, gsky: Double;
cropped: Boolean;
sinCosLUT: TPointDDynArray;
begin
if not InRange(AIndex, 0, High(FInputScans)) then
Expand All @@ -272,7 +274,7 @@ procedure TScanCorrelator.GradientsAnalyze(const arg: TVector; var func: Double;

BuildSinCosLUT(FPointsPerRevolution, sinCosLUT, t);

ri := FOutputDPI / (CAreaGroovesPerInch * FPointsPerRevolution);
ri := FOutputDPI / (CAreaGroovesPerInch * (FPointsPerRevolution - 1));

r := CAreaBegin * 0.5 * FOutputDPI;
pos := 0;
Expand All @@ -288,19 +290,35 @@ procedure TScanCorrelator.GradientsAnalyze(const arg: TVector; var func: Double;

if FInputScans[AIndex].InRangePointD(py, px) then
begin
p := FInputScans[AIndex].GetPointD(py, px, isImage, imLinear);
ct := AngleTo02Pi(t + pos * FRadiansPerRevolutionPoint);
cropped := (In02PiExtentsAngle(ct, FPerSnanCrops[AIndex, 0], FPerSnanCrops[AIndex, 1]) or
In02PiExtentsAngle(ct, FPerSnanCrops[AIndex, 2], FPerSnanCrops[AIndex, 3])) and
(rri >= rLbl);

p := NaN;
if not cropped then
p := FInputScans[AIndex].GetPointD(py, px, isImage, imLinear);

imgData[AIndex, i] := p;

if (AIndex > 0) and Assigned(grad) then
begin
gimgx := FInputScans[AIndex].GetPointD(py, px, isXGradient, imLinear);
gimgy := FInputScans[AIndex].GetPointD(py, px, isYGradient, imLinear);

gt := (gimgx * -sn + gimgy * cs) * ri;
gcx := gimgx;
gcy := gimgy;
gskx := gimgx * cs * ri;
gsky := gimgy * sn * ri;
gt := NaN;
gcx := NaN;
gcy := NaN;
gskx := NaN;
gsky := NaN;
if not cropped then
begin
gimgx := FInputScans[AIndex].GetPointD(py, px, isXGradient, imLinear);
gimgy := FInputScans[AIndex].GetPointD(py, px, isYGradient, imLinear);

gt := (gimgx * -sn + gimgy * cs) * ri;
gcx := gimgx;
gcy := gimgy;
gskx := gimgx * cs * ri;
gsky := gimgy * sn * ri;
end;

gradData[High(FInputScans) * 0 + AIndex - 1, i] := gt;
gradData[High(FInputScans) * 1 + AIndex - 1, i] := gcx;
Expand Down Expand Up @@ -341,6 +359,8 @@ procedure TScanCorrelator.GradientsAnalyze(const arg: TVector; var func: Double;
var
iX, iY, iArg, cnt: Integer;
begin
rLbl := C45RpmLabelOuterSize * 0.5 * FOutputDPI;

cnt := Ceil(CAreaWidth * CAreaGroovesPerInch * FPointsPerRevolution);
SetLength(imgData, Length(FInputScans), cnt);
SetLength(gradData, Length(grad), cnt);
Expand Down Expand Up @@ -699,8 +719,8 @@ procedure TScanCorrelator.Save;
procedure TScanCorrelator.Process;
begin
AngleInit;
Analyze;
Crop;
Analyze;
Rebuild;
end;

Expand Down

0 comments on commit 8b40f20

Please sign in to comment.