/* EDIT: Explain what this source file does
Copyright (C) 2019 Samo Penic.
This file is part of Sizif.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see . */
#include
#define DESKEW_REDUCTION 4
PIX *loadimage(char *filename){
PIX *pix, *pixt;
int format, bpp;
/* format=fileformat(filename);
// In later versions of leptonica you will have to do this
// pixReadHeader(filename, format,NULL,NULL,NULL,bpp,NULL);
if(format!=IFF_PNG && format!=IFF_JFIF_JPEG && format!=IFF_TIFF && format!=
IFF_GIF && format!=7 && format!=8){
dfprintf(stderr,"Not recognised file format %i", format);
return NULL;
} */
if ((pix = pixRead(filename)) == NULL) return NULL;
/* TODO: convert image to 1-bpp 300dpi regardless of scan */
bpp=pixGetDepth(pix);
if(bpp>1){
/*
printf("Bits per pixel=%i",bpp);
exit(1); */
//pixThresholdForFgBg(pix,5,100,NULL,NULL);
//pixContrastTRC(pix, pix, 1000);
pixt = pixContrastNorm(NULL, pix, 10, 10, 40, 2, 2);
pixDestroy(&pix);
pix = pixGammaTRC(NULL, pixt, 1.5, 50, 235);
pixt=pixThresholdToBinary(pix, 200);
//pixt=pixThreshold8(pix,1,1,0);
pixDestroy(&pix);
pix=pixt;
}
return pix;
}
PIX *lineremoval(PIX *pixs){
PIX *pixd = pixMorphCompSequence(pixs, "o2.2", 0); /* Odstranimo pikice o2.2*/
return pixd;
}
float deskew(PIX *pix){
float angle;
PIX *pixd1;
pixd1=pixFindSkewAndDeskew(pix, DESKEW_REDUCTION, &angle, NULL);
return angle;
}
float repair_scanned_image(PIX *pixs){
PIX *pixd= lineremoval(pixs);
float angle=deskew(pixd);
return angle;
}
float get_scan_angle(char *filename){
PIX *pix=loadimage(filename);
if (pix==NULL) return 0.0;
return repair_scanned_image(pix);
}