Giter Club home page Giter Club logo

Comments (4)

yashlamba avatar yashlamba commented on June 14, 2024

This could be a simple weird cropping issue @sakshamarora1.

from handwrite.

chriscohoat avatar chriscohoat commented on June 14, 2024

Hey @yashlamba I encountered the same thing, but I found that if I converted my scanned image to a gray-scale image and then only used pixels that were below a certain darkness threshold it improved the quality.

Original on the left and cleaned version on the right:

CleanShot 2021-12-19 at 14 14 58@2x

Font improvement:

CleanShot 2021-12-19 at 14 18 36@2x

The code I wrote is here, happy to help make a PR if you like.

scanned_jpg = os.path.join(self.sheets_path, "with_lines.jpg")

cleaned_image = cv2.imread(scanned_jpg)
original_image_in_gray = cv2.cvtColor(cleaned_image, cv2.COLOR_BGR2GRAY)
threshold_level = 150
# To get specific coordinates of the pixels, use the following line:
# coords = np.column_stack(np.where(gray < threshold_level))
# Create mask of all pixels lower than threshold level
mask = original_image_in_gray < threshold_level
# Color the pixels in the mask
cleaned_image[mask] = (0, 0, 0)
# Remove all pixels not in the mask
cleaned_image[~mask] = (255, 255, 255)
# Convert jpg_img to cv2.COLOR_BGR2GRAY
updated_image = cv2.cvtColor(cleaned_image, cv2.COLOR_BGR2GRAY)

both_images = np.concatenate((original_image_in_gray, updated_image), axis=1)

cv2.imshow('Side by Side', both_images)
cv2.waitKey()

from handwrite.

yashlamba avatar yashlamba commented on June 14, 2024

Hi @chriscohoat, The new output looks much better (We also use something very similar but a different approach) but the threshold value you used is something we are trying to figure out.

If you look here: https://github.com/cod-ed/handwrite/blob/440f59153fe02fc96503fd87f9c64b105c8ceb71/handwrite/sheettopng.py#L79-L92

We default to a threshold of 200, if I am not wrong and it is configurable, @sakshamarora1 will have more context on this. We also have #3 open for a long time to fix this. In short, the problem we have is that the threshold that worked for your input might not work for others, maybe figuring it out dynamically based on the input would be interesting.

More related to #68.

from handwrite.

sakshamarora1 avatar sakshamarora1 commented on June 14, 2024

Hi @chriscohoat . The new output looks a lot better! As @yashlamba said we need to figure out how to dynamically set the best threshold value in order to get better results just like you did.

Also, the default threshold_value is configurable here in the config json file:
https://github.com/cod-ed/handwrite/blob/440f59153fe02fc96503fd87f9c64b105c8ceb71/handwrite/default.json#L1-L2

This was initially done so that everyone can set it accordingly as each input is different. I've opened an issue to track this since I missed it before - #70

from handwrite.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.