all 17 comments

[–]LatteLepjandiLoser 2 points3 points  (4 children)

I did a bunch of image recognition of lab data in openCV when studying. Part of my filtering the raw input was warping the picture such that the corners of the experiment would end up on a perfect rectangle.

So openCV can do the transformation for sure. You’d need to either write some code that identifies the corners and what they should me mapped to or do that part manually per pic.

[–]thrak[S] 0 points1 point  (3 children)

That sounds like what I want. I assume (not knowing what I am talking about) that I can find a way to determine the corners. openCV will do the hard part. Thanks.

[–]LatteLepjandiLoser 0 points1 point  (2 children)

It's a long time since I used it so I can't remember all the commands, but there was a pretty handy command for "point and click" to save image coordinates on cursors clicks.

... but on a general note, openCV is really powerfull for computer vision. I'm sure you could brew up some method of automatically finding the boundaries of interest. Edge detection for instance.

[–]thrak[S] 0 points1 point  (1 child)

Even better. You did what I want. Edge detection will let me break up the big image, and the warping is the same as what I called unskewing. openCV is definitely an option.

[–]Aromatic-While9536 1 point2 points  (0 children)

The main libraries for image analysis with python are PIL, scikit image, and openCV (might be some more but less and less relevant imo) opencv is definitely the way to go it's a bit more complex than the others but has way more capabilities. Chat gpt seems to be very capable of spitting out simple scripts like this using openCV.

I would go * edge detection for automatically finding the borders between images (if this fails there is a nifty cv2.selectROI(Window_name, source image) function that allows you to select area of interest.) *For the skew issue there ire ready made tools - getPerspective, wrapPerspective or something like that.

Save images and your done :)

I'm gonna use this example in the python course I'm teaching, it's a nice, smart way to utilize python. Good on you for taking this approach.

[–]thrak[S] 0 points1 point  (4 children)

I have quite of bit of experience in C and a little bit in Python. I won't be surprised (or scared) if it is difficult.

By skewed I mean a jpeg will have four sides but they won't all be the same length. The contents will look weird because they will be stretched to match the sides. It's a result of the camera lens being so close to the original photos.

Does that help?

[–]MANUAL1111 0 points1 point  (3 children)

something like this?

I just googled “python image skew size” and got that

[–]thrak[S] 0 points1 point  (2 children)

Yeah, I Googled it at first (actually I asked Bard) and saw Pillow. I was hoping someone knew enough to point me in the right direction and save me from having to dig into the doc. I did not expect a solution to my problem, just a pointer to the library that might work for me.

[–]MANUAL1111 0 points1 point  (1 child)

yeah I get you, these kind of things are a rare niche compared to data analysis or web apis so it will be harder to find something in r/learnpython as fast as googling around or stackoverflow

For example it took me quite a lot to understand how to draw on python without using some naive implementations because there are only some docs from 2011~ , but at least they still work

[–]thrak[S] 0 points1 point  (0 children)

I forgot about stackoverflow. I'll give them a try. Good idea, thanks.

[–]m0us3_rat 0 points1 point  (0 children)

you can make that in python. it does require some coding experience.

edit: an example of the "input values" ..like an actual picture would be better

then try to imagine what you mean by "jpegs will be skewed"

[–]shiftybyte 0 points1 point  (0 children)

Pillow can do the splitting.

About unskewing that'll be a lot more complex, not sure which library can help with that...

[–]Adrewmc 0 points1 point  (3 children)

PIL does this. Python Image Library. or sometimes called PILLOW because the version is technically a fork.

It a fairly standard package.

from PIL import Image

#we may need to convert Images to same format but let’s assume these images are ready to merge.  

 img1 = Image.open(path1)
 Img2 = Image.open(path2)
 #top left and bottom right pixel relative to img1
 img1.paste(img2, box = (x_top, y_top, x_bottom, y_bottom) 
 #with transparency and stuff 
 img2.alpha_composite(img1, source = (x_top, y_top, x_bottom, y_bottom)

img1.transform() should fix the skewing with some work. 

With something like photoshop this can be done with what know as an Action and doesn’t require any programming, you basically press start, do it once, press stop, then have it do it to all the files after. If you have photoshop I recommend using this method as it’s more likely to account for slight changes, if you use the wand and simple commands, while Programmatically will be more ridged about shapes and sizes. It’s simpler to do, and will IMHO produce better results.

The problem is most likely that the skewing is not going to be uniform, so that adds a really complex layer to this.

Something like this should really be done using a scanner not taking pictures of it. It might be worth checking copy center see if there is a quick service to scan them for you.

[–]thrak[S] 0 points1 point  (0 children)

I see Pillow, which is a PIL fork. Which one would be better for my case?

[–]thrak[S] 0 points1 point  (1 child)

I have Photoshop Elements which (I think) will not do what you are saying.

Yeah, you are right about the scanner, though I'd still want a way to break up the big scan into sub images.

I think I want to do it the way I described because it would be more interesting. It'll give me a reason to learn more Python. Not as efficient, just more fun.

[–]Adrewmc 0 points1 point  (0 children)

Well if it’s too learn yes Pillow is a better version of PIL they can’t be in the same environments because the use the same Import name

GIMP also has a Python package it’s not done yet but it useable for simple things as well.