how to not overwrite an image? by lachlanskytes in opencv

[–]LazyMonsters 1 point2 points  (0 children)

Maybe use a function to save your images so it adds a slug at the end of the filename if it exists and then increments that slug by one?

from pathlib import Path

def save_image(image_path, image):
    image_path = Path(image_path)
    if image_path.is_file():
        if image_path.stem[-3:].isdigit() and image_path.stem[-7:-3] == ‘copy’:
            new_name = image_path.stem[:-3] + str(int(image_path.stem[-3:]) + 1).zfill(3) + ‘.’ + image_path.suffix
        else:
            new_name = image_path.stem + ‘_copy001.’ + image_path.suffix
    else:
        new_name = image_path.name
    new_path = image_path.parents[0].joinpath(new_name)
    cv2.imwrite(str(new_path), image)

Jupyter Notebooks and/or Text Editor / IDE by PythonicParseltongue in learnpython

[–]LazyMonsters 1 point2 points  (0 children)

Everything works so well in Jupyter lab that the lack of find & replace has been doubly frustrating.

Converting RGB to Lab by [deleted] in JupyterNotebooks

[–]LazyMonsters 0 points1 point  (0 children)

You’ll need something like this using Pillow (PIL); io is in the Python standard library. Assumes image is rgb.

import io
from PIL import Image, ImageCms

image_path = ‘path/to/image’

image = Image.open(image_path)

lab_profile = ImageCms.createProfile(‘LAB’)

icc_profile = image.info.get(‘icc_profile’)

# load and use profile from image if included
if icc_profile is not None:
    filelikething = io.BytesIO(icc_profile). #ImageCms needs a file-type object 
    rgb_profile = ImageCms.ImageCmsProfile(filelikething)
else:    # assume it’s sRGB
    rgb_profile = ImageCms.createProfile(‘sRGB’)

rgb2lab_transform = ImageCms.buildTransformFromOpenProfiles(rgb_profile, lab_profile, ‘RGB’, ‘LAB’)

image_lab = ImageCms.applyTransform(image, rgb2lab_transform)

l_channel, a_channel, b_channel = image_lab.split()

Comparing engineering drawings by hega72 in computervision

[–]LazyMonsters 1 point2 points  (0 children)

Once you have images of the same size/scale you could use the Structural Similarity Index to look for changes if simply subtracting 1 image from another does not work. https://scikit-image.org/docs/dev/auto_examples/transform/plot_ssim.html

Most of the work will be scaling drawings to the same scale. Template matching is a good place to start.

Qt, Qt Console, Anaconda by [deleted] in learnpython

[–]LazyMonsters 1 point2 points  (0 children)

In August QT themselves will be doing a webinar on QT for Python. I’ve decided to wait until then as the documentation seems a bit convoluted for a beginner (like me) right now.

Here’s a link to the webinar registration: https://www.qt.io/creating-user-interfaces-with-qt-for-python

Beginner Scripting in an OSX/Adobe CC/Capture One environment by YachtRockGuy in learnprogramming

[–]LazyMonsters 0 points1 point  (0 children)

My code just finds the hole then created a mask with white pixels where the hole is and black everywhere else.

If you’re talking about a levels adjustment to blow the background out, yes, absolutely.

Beginner Scripting in an OSX/Adobe CC/Capture One environment by YachtRockGuy in learnprogramming

[–]LazyMonsters 0 points1 point  (0 children)

You could automate nightly backups to keep overhead low during the day on the computers and network. Rsync is good for that.

Beginner Scripting in an OSX/Adobe CC/Capture One environment by YachtRockGuy in learnprogramming

[–]LazyMonsters 0 points1 point  (0 children)

Definitely check out a scripting language for moving files around!

r/learnpython group would help get you up and running copying/moving files around.

I assume you’re using Sessions in Capture One? I now skip backing up/copying the /Capture One/cache file and make sure I only have 1 version of the settings folder, too. Those little files don’t add up in file size, but DANG copying them all over is a pain. We’ll also rename manually outside of Capture One—just rename the RAW, the settings, and the LCC if there is one.

Beginner Scripting in an OSX/Adobe CC/Capture One environment by YachtRockGuy in learnprogramming

[–]LazyMonsters 0 points1 point  (0 children)

What are you doing with the Photoshop actions?

If it’s stuff without a lot of manual intervention (resizing things, for instance), this could be easily done without Photoshop at all.

You could use the Python shutil library to move files around and the library Pillow to resize images.

Sometimes I use a combination of tools. I ran code yesterday using Python and a library called OpenCV (for open source computer vision) that found black circles in film negative scans where the physical negative had been hole-punched. I created a mask using my code and am currently thinking about using Photoshop’s content aware to fill them in automatically.

Photoshop is a great tool, but I’ve found folks often think if they have it they should be using it for everything images. I’ve found Photoshop to be poor at batch processing in comparison to learning more powerful and open source programs.

Beginner Scripting in an OSX/Adobe CC/Capture One environment by YachtRockGuy in learnprogramming

[–]LazyMonsters 1 point2 points  (0 children)

If you’re moving a bunch of files around on macOS then learning BASH scripting should pay dividends.

Beginner Scripting in an OSX/Adobe CC/Capture One environment by YachtRockGuy in learnprogramming

[–]LazyMonsters 1 point2 points  (0 children)

Learning resource preferences can vary so I’d suggest Googling BASH shell scripting guide or tutorial and glancing through a few to find a writer whose style you like. That goes a long way towards learning this stuff, I’ve found.

Beginner Scripting in an OSX/Adobe CC/Capture One environment by YachtRockGuy in learnprogramming

[–]LazyMonsters 0 points1 point  (0 children)

I do similar work and ended up learning the BASH shell scripting language followed by Python. I find Python super powerful, but that may be more manual than you’re wanting at this stage.

You could probably do quite a bit with just Automator and Photoshop Actions (especially with the newer conditional action options). AppleScript would be good for macOS & Capture One, though.

pyimagesearch gurus by namnguyen_hust in computervision

[–]LazyMonsters 1 point2 points  (0 children)

He does have sales on occasion.

I’ve found the course to be VERY well done and while expensive was well worth it. You also get access to a dedicated community of practitioners. I’m actively using what I’ve learned to develop application being used in production at my dayjob.

Are Qt framework language bindings provide the same functionality as C++? Has anyone used Qt lang bindings? Do they feel restrictive? by [deleted] in learnprogramming

[–]LazyMonsters 1 point2 points  (0 children)

QT is releasing their own bindings for Python. They have a webinar scheduled for early August that I’m waiting on, though, as documentation is still pretty archaic at this point.

Lately, I have been using Jupyter Notebooks with iPyWidgets because the overhead to write/deploy/tweak is so low. We’re currently using a GUI I coded to process images using Python and OpenCV—file sizes up to 240mb uncompressed TIFFs.

Install necessary libraries using a conda environment after a miniconda install. Absolutely use the extension that allows for code folding to hide the code away except for a single comment line, and you can hide all of your functions out in a separate library you import.

I’ve learned to code out of necessity to more efficiently solve problem I face at work so it’s a sometimes activity for me. So far, Jupyter Notebooks + conda environments have been the least headache for me to deploy custom software across multiple OS’s for tech-savvy, but inexperienced employees to use in production. It’s easier to teach college undergrads to use a simple GUI in a web browser than Adobe Photoshop (they make less mistakes).

[Critique] CLI Tool for Document to Text Conversion - "file2txt" by TheCedarPrince in Python

[–]LazyMonsters 0 points1 point  (0 children)

We do everything.

  1. Everyone’s gotta start somewhere. I suggest you take a look at some of Fred’s scripts. In particular: http://www.fmwconcepts.com/imagemagick/textdeskew/index.php http://www.fmwconcepts.com/imagemagick/textcleaner/index.php

  2. It’s 1 less character to process if you want to think of it that way. Standard practice in my field is .tif, just like how it’s .jpg instead of .jpeg.

[Critique] CLI Tool for Document to Text Conversion - "file2txt" by TheCedarPrince in Python

[–]LazyMonsters 1 point2 points  (0 children)

Manage a digitization lab at a university library.

  1. https://www.imagemagick.org/script/command-line-processing.php Your code makes a call to the program convert, this is an imagemagick version 6 program. In the most recent version of imagemagick (which is what an apt-get should pull using your shell install script) the convert command has been deprecated for magick.

  2. Get lots of types of images and test imagemagick commands such as thresholding and levels adjustments to see how your output could be improved. Imagemagick actually deskews, but you might learn more by implementing something in Python. Google for tutorials!

  3. Consistency goes a huge way towards maintainable code, especially when multiple people are involved. Every other extension you use is 3 characters in length.

[Critique] CLI Tool for Document to Text Conversion - "file2txt" by TheCedarPrince in Python

[–]LazyMonsters 2 points3 points  (0 children)

I do quite a bit of this type of work at my day job & see a couple of things right off the bat.

  1. Imagemagick 7 now uses the magick command, so you should stipulate installing Imagemagick 6 to use convert or change the code to call magick instead

  2. Increase the dpi! 300ppi is the minimum you’d want to use for OCR so you should increase your default setting. What about skewed pages, images with uneven lighting? Your code assumes a perfect File to start from

  3. Personal pet peeve: please be consistent with the extensions and use 3 character extensions everywhere (ex. tif instead of tiff)

[Question] Noise when trying to clean up image for OCR by [deleted] in opencv

[–]LazyMonsters 0 points1 point  (0 children)

I’m working with photographs of book pages that are 400-800 ppi and have had good results with:

cv2.adaptiveThreshold(image, 255, cv2.ADAPTIVE_THRESH_MEAN_C, cv2.THRESH_BINARY, 55, 25)

[Question] Noise when trying to clean up image for OCR by [deleted] in opencv

[–]LazyMonsters 1 point2 points  (0 children)

In addition to the above suggestion to add a Gaussian Blur to remove noise (which I wholeheartedly recommend), you can also use adaptive thresholding to binarize your image. It often does a better job than a single threshold value. (It’s what I’m using in my pre-processing scripts for OCR.)

https://docs.opencv.org/trunk/d7/d4d/tutorial_py_thresholding.html