1

I am using this python scripts https://github.com/mzucker/page_dewarp, which manages the rendering and the color conversion of the images with adaptiveThreshold (from OpenCV) and pillow.

I would ask if it is possibile to modify the script in order to obtain an eight colors grayscale image instead of the default bitonal.

I am quite new to python, but I think that the part of the code to edit is this:

img_gray = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)

remapped = cv2.remap(img_gray, image_x_coords, image_y_coords,
                     cv2.INTER_CUBIC,
                     None, cv2.BORDER_REPLICATE)

thresh = cv2.adaptiveThreshold(remapped, 255, cv2.ADAPTIVE_THRESH_MEAN_C,
                               cv2.THRESH_BINARY, ADAPTIVE_WINSZ, 25)

pil_image = Image.fromarray(thresh)
 pil_image = pil_image.convert('L')

threshfile = name + '_thresh.png'
pil_image.save(threshfile, dpi=(OUTPUT_DPI, OUTPUT_DPI))

It will be good if it is possible to eliminate the image thresholding and mantain only the dewarping feature, thus preserving the image as in the input.

EDIT: I added two examples:

(1) expected output: enter image description here

(2) actual output: enter image description here

Here is the input image: enter image description here

qwertxyz
  • 143
  • 1
  • 7
  • do you want uniformly distributed normalized colors? you could linearly normalize between 0 and 255, then divide by 62 and multiply by 62 again. – Micka Feb 02 '17 at 07:33
  • If I alter the number 255 it changes only the background color. I edited the question adding two examples of the expected (1) and actual (2) output – qwertxyz Feb 02 '17 at 09:05
  • after thresholding it's too late, you'll have to replace the thresholding by a clustering or color-reduction. If you just want to make it a bit "smoother" you can smooth the thresholded image by gaussian blur. – Micka Feb 02 '17 at 09:09
  • Thank you! How can I do that? I'm a bit new to python, could you suggest some code modifications? – qwertxyz Feb 02 '17 at 09:10
  • can you post the input image, too? – Micka Feb 02 '17 at 09:12
  • I posted the input image. Please note that in order to obtain proper margins you need to set to "0" the values of PAGE_MARGIN_X and PAGE_MARGIN_Y – qwertxyz Feb 02 '17 at 09:15
  • It will be good if it is possible to eliminate the image thresholding and mantain only the dewarping feature, preserving the image as in the input – qwertxyz Feb 02 '17 at 10:52

0 Answers0