主题:[求助]语言脚本编辑
下面是图像处理的两个脚本,据说是类似PASKAL语言,所以,请教诸位高手。
第一步获得SdWidth、SdHeight,第二步运用它来处理图像。(前者是IntToStr(X2-X1),后者是IntToStr(Y2-Y1)。)
我想要是语言能够把两部分合二为一,就自动化了。能做到吗?
以下脚本可以自动获得标准页面的版心尺寸:
SkewAngle:=ImgDeskew( _CurrentImage, 10, 0.1, 0, False, False );
// Get Center Data
ImgInvert(_CurrentImage);
X1:=ImgFindBlackBorderLeft(_CurrentImage, 99.5, 1);
Y1:=ImgFindBlackBorderTop(_CurrentImage, 99.5, 1);
X2:=ImgFindBlackBorderRight(_CurrentImage, 99.5, 1);
Y2:=ImgFindBlackBorderBottom(_CurrentImage, 99.5, 1);
MiniBorder:=(X2-X1) div 28;
ImgInvert(_CurrentImage);
ImgCropBorder( _CurrentImage, X1-MiniBorder, Y1-MiniBorder, X2+MiniBorder, Y2+MiniBorder);
OutPutData:=IntToStr(X2-X1)+' _ '+IntToStr(Y2-Y1);
ApplicationLog(OutPutData);
以下脚本可以自动对齐版心,需要手动输入版心尺寸。可以自动过滤版心四周的污渍、黑边等等。
//Input Data
SdWidth:=1540;
SdHeight:=2605;
MiniBorder:=SdWidth div 28;
// Updating log with description of next operation
ApplicationLog( 'Image Black Border Removal...' );
// Apply BLACK BORDER REMOVAL on the image
// Method : Absolute black percentage
// Min black %: 99
// Max holes: 1
// Borders: Clean
// Clean residues: No
Left:=ImgFindBlackBorderLeft( _CurrentImage, 99.0, 1 );
Top:=ImgFindBlackBorderTop( _CurrentImage, 99.0, 1 );
Right:=ImgFindBlackBorderRight( _CurrentImage, 99.0, 1 );
Bottom:=ImgFindBlackBorderBottom( _CurrentImage, 99.0, 1 );
ImgCleanBorder( _CurrentImage, Left, Top, Right, Bottom );
// Updating log with description of next operation
ApplicationLog( 'Image Despeckling...' );
// Apply ZONAL DESPECKLE on the image
// Max points size: 3 x 3
// Min Point Density: 5
// Tile size: 30
ImgDespeckleZonal( _CurrentImage, 3, 3, 5, 30 );
// Updating log with description of next operation
ApplicationLog( 'Image Deskewing...' );
// Apply DESKEW on the image
// Range: -10/+10?
// Resolution: 0.1?
// Step: Automatic
// Background: White
// Interpolation: No
SkewAngle:=ImgDeskew( _CurrentImage, 10, 0.1, 0, False, False );
// Smart Center
ImgInvert(_CurrentImage);
X1:=ImgFindBlackBorderLeft(_CurrentImage, 99.0, 1);
X2:=ImgFindBlackBorderRight(_CurrentImage, 99.0, 1);
CanvasWidth:=ImgGetWidth(_CurrentImage);
CanvasHeight:=ImgGetHeight(_CurrentImage);
SdX1:=((CanvasWidth-SdWidth) div 2);
SdX2:=CanvasWidth-SdX1;
SdMiniY:=(CanvasHeight-SdHeight) div 8;
if X2-X1<SdWidth then
begin
intTemp:=(SdWidth+X1-X2) div 2;
X1:=x1-intTemp;
X2:=X2+intTemp;
end;
if ((X1+MiniBorder<SdX1) and (X2-MiniBorder>SdX2)) then
begin
imgTemp:=ImgCopy(_CurrentImage, X1+MiniBorder, 0, X2-MiniBorder, CanvasHeight);
X1Temp:=ImgFindBlackBorderLeft(imgTemp, 99.0, 1);
X2Temp:=ImgFindBlackBorderRight(imgTemp, 99.0, 1);
if X1Temp>MiniBorder then X1:=X1+MiniBorder+X1Temp;
if X2-X2Temp>MiniBorder then X2:=X1+MiniBorder+X2Temp;
ImgDelete(imgTemp);
end;
if X1>CanvasWidth-X2 then
begin
CutLeft:=X1-MiniBorder;
CutRight:=X1+SdWidth+MiniBorder;
// ImgCropBorder( _CurrentImage, X1-MiniBorder, 0, X1+SdWidth+MiniBorder, CanvasHeight)
end
else
begin
CutLeft:=(X2-SdWidth)-MiniBorder;
CutRight:=X2+MiniBorder;
end;
if CutLeft<0 then CutLeft:=0;
if CutRight>CanvasWidth then CutRight:=CanvasWidth;
ImgCropBorder( _CurrentImage, CutLeft, 0, CutRight, CanvasHeight);
Y1:=ImgFindBlackBorderTop(_CurrentImage, 99.3, 1);
Y2:=ImgFindBlackBorderBottom(_CurrentImage, 99.3, 1);
if ((Y1<SdMiniY) or (Y2>CanvasHeight-SdMiniY)) then
begin
imgTemp:=ImgCopy(_CurrentImage, 0, SdMiniY, SdWidth+MiniBorder*2, CanvasHeight-SdMiniY);
if Y1<SdMiniY then
begin
Y1Temp:=ImgFindBlackBorderTop(imgTemp, 99.3, 1);
if Y1Temp>SdMiniY then Y1:=Y1Temp+SdMiniY;
end;
if Y2>CanvasHeight-SdMiniY then
begin
Y2temp:=ImgFindBlackBorderBottom(imgTemp, 99.3, 1);
if Y2temp<CanvasHeight-SdMiniY*2 then Y2:=Y2temp+SdMiniY;
end;
ImgDelete(imgTemp);
end;
if Y1>CanvasHeight-Y2 then Y1:=Y2-SdHeight else Y2:=Y1+SdHeight;
if Y1<MiniBorder then Y1:=MiniBorder;
if Y2>CanvasHeight-MiniBorder then Y2:=CanvasHeight-MiniBorder;
ImgCropBorder( _CurrentImage, 0, Y1-MiniBorder, SdWidth+MiniBorder*2, Y2+MiniBorder);
ImgResize(_CurrentImage, SdWidth+MiniBorder*8, SdHeight+MiniBorder*8, 0);
ImgInvert(_CurrentImage);
ImgShift(_CurrentImage, MiniBorder*3, MiniBorder*3);
第一步获得SdWidth、SdHeight,第二步运用它来处理图像。(前者是IntToStr(X2-X1),后者是IntToStr(Y2-Y1)。)
我想要是语言能够把两部分合二为一,就自动化了。能做到吗?
以下脚本可以自动获得标准页面的版心尺寸:
SkewAngle:=ImgDeskew( _CurrentImage, 10, 0.1, 0, False, False );
// Get Center Data
ImgInvert(_CurrentImage);
X1:=ImgFindBlackBorderLeft(_CurrentImage, 99.5, 1);
Y1:=ImgFindBlackBorderTop(_CurrentImage, 99.5, 1);
X2:=ImgFindBlackBorderRight(_CurrentImage, 99.5, 1);
Y2:=ImgFindBlackBorderBottom(_CurrentImage, 99.5, 1);
MiniBorder:=(X2-X1) div 28;
ImgInvert(_CurrentImage);
ImgCropBorder( _CurrentImage, X1-MiniBorder, Y1-MiniBorder, X2+MiniBorder, Y2+MiniBorder);
OutPutData:=IntToStr(X2-X1)+' _ '+IntToStr(Y2-Y1);
ApplicationLog(OutPutData);
以下脚本可以自动对齐版心,需要手动输入版心尺寸。可以自动过滤版心四周的污渍、黑边等等。
//Input Data
SdWidth:=1540;
SdHeight:=2605;
MiniBorder:=SdWidth div 28;
// Updating log with description of next operation
ApplicationLog( 'Image Black Border Removal...' );
// Apply BLACK BORDER REMOVAL on the image
// Method : Absolute black percentage
// Min black %: 99
// Max holes: 1
// Borders: Clean
// Clean residues: No
Left:=ImgFindBlackBorderLeft( _CurrentImage, 99.0, 1 );
Top:=ImgFindBlackBorderTop( _CurrentImage, 99.0, 1 );
Right:=ImgFindBlackBorderRight( _CurrentImage, 99.0, 1 );
Bottom:=ImgFindBlackBorderBottom( _CurrentImage, 99.0, 1 );
ImgCleanBorder( _CurrentImage, Left, Top, Right, Bottom );
// Updating log with description of next operation
ApplicationLog( 'Image Despeckling...' );
// Apply ZONAL DESPECKLE on the image
// Max points size: 3 x 3
// Min Point Density: 5
// Tile size: 30
ImgDespeckleZonal( _CurrentImage, 3, 3, 5, 30 );
// Updating log with description of next operation
ApplicationLog( 'Image Deskewing...' );
// Apply DESKEW on the image
// Range: -10/+10?
// Resolution: 0.1?
// Step: Automatic
// Background: White
// Interpolation: No
SkewAngle:=ImgDeskew( _CurrentImage, 10, 0.1, 0, False, False );
// Smart Center
ImgInvert(_CurrentImage);
X1:=ImgFindBlackBorderLeft(_CurrentImage, 99.0, 1);
X2:=ImgFindBlackBorderRight(_CurrentImage, 99.0, 1);
CanvasWidth:=ImgGetWidth(_CurrentImage);
CanvasHeight:=ImgGetHeight(_CurrentImage);
SdX1:=((CanvasWidth-SdWidth) div 2);
SdX2:=CanvasWidth-SdX1;
SdMiniY:=(CanvasHeight-SdHeight) div 8;
if X2-X1<SdWidth then
begin
intTemp:=(SdWidth+X1-X2) div 2;
X1:=x1-intTemp;
X2:=X2+intTemp;
end;
if ((X1+MiniBorder<SdX1) and (X2-MiniBorder>SdX2)) then
begin
imgTemp:=ImgCopy(_CurrentImage, X1+MiniBorder, 0, X2-MiniBorder, CanvasHeight);
X1Temp:=ImgFindBlackBorderLeft(imgTemp, 99.0, 1);
X2Temp:=ImgFindBlackBorderRight(imgTemp, 99.0, 1);
if X1Temp>MiniBorder then X1:=X1+MiniBorder+X1Temp;
if X2-X2Temp>MiniBorder then X2:=X1+MiniBorder+X2Temp;
ImgDelete(imgTemp);
end;
if X1>CanvasWidth-X2 then
begin
CutLeft:=X1-MiniBorder;
CutRight:=X1+SdWidth+MiniBorder;
// ImgCropBorder( _CurrentImage, X1-MiniBorder, 0, X1+SdWidth+MiniBorder, CanvasHeight)
end
else
begin
CutLeft:=(X2-SdWidth)-MiniBorder;
CutRight:=X2+MiniBorder;
end;
if CutLeft<0 then CutLeft:=0;
if CutRight>CanvasWidth then CutRight:=CanvasWidth;
ImgCropBorder( _CurrentImage, CutLeft, 0, CutRight, CanvasHeight);
Y1:=ImgFindBlackBorderTop(_CurrentImage, 99.3, 1);
Y2:=ImgFindBlackBorderBottom(_CurrentImage, 99.3, 1);
if ((Y1<SdMiniY) or (Y2>CanvasHeight-SdMiniY)) then
begin
imgTemp:=ImgCopy(_CurrentImage, 0, SdMiniY, SdWidth+MiniBorder*2, CanvasHeight-SdMiniY);
if Y1<SdMiniY then
begin
Y1Temp:=ImgFindBlackBorderTop(imgTemp, 99.3, 1);
if Y1Temp>SdMiniY then Y1:=Y1Temp+SdMiniY;
end;
if Y2>CanvasHeight-SdMiniY then
begin
Y2temp:=ImgFindBlackBorderBottom(imgTemp, 99.3, 1);
if Y2temp<CanvasHeight-SdMiniY*2 then Y2:=Y2temp+SdMiniY;
end;
ImgDelete(imgTemp);
end;
if Y1>CanvasHeight-Y2 then Y1:=Y2-SdHeight else Y2:=Y1+SdHeight;
if Y1<MiniBorder then Y1:=MiniBorder;
if Y2>CanvasHeight-MiniBorder then Y2:=CanvasHeight-MiniBorder;
ImgCropBorder( _CurrentImage, 0, Y1-MiniBorder, SdWidth+MiniBorder*2, Y2+MiniBorder);
ImgResize(_CurrentImage, SdWidth+MiniBorder*8, SdHeight+MiniBorder*8, 0);
ImgInvert(_CurrentImage);
ImgShift(_CurrentImage, MiniBorder*3, MiniBorder*3);