commit | author | age
|
5d5578
|
1 |
/* EDIT: Explain what this source file does |
SP |
2 |
Copyright (C) 2019 Samo Penic. |
|
3 |
|
|
4 |
This file is part of Sizif. |
|
5 |
|
|
6 |
This program is free software: you can redistribute it and/or modify |
|
7 |
it under the terms of the GNU General Public License as published by |
|
8 |
the Free Software Foundation, either version 3 of the License, or |
|
9 |
(at your option) any later version. |
|
10 |
|
|
11 |
This program is distributed in the hope that it will be useful, |
|
12 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
GNU General Public License for more details. |
|
15 |
|
|
16 |
You should have received a copy of the GNU General Public License |
|
17 |
along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
|
18 |
|
|
19 |
#include <leptonica/allheaders.h> |
|
20 |
#define DESKEW_REDUCTION 4 |
|
21 |
|
|
22 |
PIX *loadimage(char *filename){ |
|
23 |
PIX *pix, *pixt; |
|
24 |
int format, bpp; |
|
25 |
/* format=fileformat(filename); |
|
26 |
// In later versions of leptonica you will have to do this |
|
27 |
// pixReadHeader(filename, format,NULL,NULL,NULL,bpp,NULL); |
|
28 |
if(format!=IFF_PNG && format!=IFF_JFIF_JPEG && format!=IFF_TIFF && format!= |
|
29 |
IFF_GIF && format!=7 && format!=8){ |
|
30 |
dfprintf(stderr,"Not recognised file format %i", format); |
|
31 |
return NULL; |
|
32 |
} */ |
|
33 |
if ((pix = pixRead(filename)) == NULL) return NULL; |
|
34 |
|
|
35 |
/* TODO: convert image to 1-bpp 300dpi regardless of scan */ |
|
36 |
bpp=pixGetDepth(pix); |
|
37 |
if(bpp>1){ |
|
38 |
/* |
|
39 |
printf("Bits per pixel=%i",bpp); |
|
40 |
exit(1); */ |
|
41 |
//pixThresholdForFgBg(pix,5,100,NULL,NULL); |
|
42 |
//pixContrastTRC(pix, pix, 1000); |
|
43 |
pixt = pixContrastNorm(NULL, pix, 10, 10, 40, 2, 2); |
|
44 |
pixDestroy(&pix); |
|
45 |
pix = pixGammaTRC(NULL, pixt, 1.5, 50, 235); |
|
46 |
pixt=pixThresholdToBinary(pix, 200); |
|
47 |
//pixt=pixThreshold8(pix,1,1,0); |
|
48 |
pixDestroy(&pix); |
|
49 |
pix=pixt; |
|
50 |
} |
|
51 |
return pix; |
|
52 |
} |
|
53 |
|
|
54 |
PIX *lineremoval(PIX *pixs){ |
|
55 |
PIX *pixd = pixMorphCompSequence(pixs, "o2.2", 0); /* Odstranimo pikice o2.2*/ |
|
56 |
return pixd; |
|
57 |
} |
|
58 |
|
|
59 |
float deskew(PIX *pix){ |
|
60 |
float angle; |
|
61 |
PIX *pixd1; |
|
62 |
pixd1=pixFindSkewAndDeskew(pix, DESKEW_REDUCTION, &angle, NULL); |
|
63 |
return angle; |
|
64 |
} |
|
65 |
|
|
66 |
|
|
67 |
float repair_scanned_image(PIX *pixs){ |
|
68 |
PIX *pixd= lineremoval(pixs); |
|
69 |
float angle=deskew(pixd); |
|
70 |
return angle; |
|
71 |
} |
|
72 |
|
|
73 |
float get_scan_angle(char *filename){ |
|
74 |
PIX *pix=loadimage(filename); |
|
75 |
if (pix==NULL) return 0.0; |
|
76 |
return repair_scanned_image(pix); |
|
77 |
} |
|
78 |
|