0

I have a photo that I am trying to use to template a DXF file for laser cutting. The photo has a square rule for use as a scale bar, however it is somewhat off angle such that the right angle is slightly off and the vertical and horizontal scale bars are also not quite correct.

Is there a way transform this image in Inkscape to correct (or approximate a correction) this issue? Do I just need to recapture the image with better alignment? I have another image for the other side of the bus, but it's even worse.

I tried the Perspective extension (by mapping the path onto a rectangle with the correct aspect ratio) but this didn't seem to help at all with correcting the angle. I clearly don't quite understand how perspective works, and don't know what other options might exist.

Thank you in advance! Images below.

Photo with a traced path over the desired cutout and the ruler (22in x 13in)

The traced path showing the slight distortion

1
  • Inkscape is a vector image editor, and has very limited raster image capabilities. You would be better trying to rectify the issue in a raster image editor first, such as GIMP/Photoshop. These have corrective rotation/perspective options for photographs built in. Then once the image is correct, import it back into Inkscape for the rest of the work. Also note that corrective perspective distortion could technically change the aspect ratio of the image, effectively squishing it, so you may also need physical measurements of the object to check it, so you can stretch it back to the proper size.
    – Billy Kerr
    Nov 5, 2023 at 23:38

1 Answer 1

0

Your case is not hopeless. Your photo (not our screenshot) probably has enough pixels for the wanted accuracy. For ex if you want to see 0,5 millimeter accurately the photo should have at least one pixel per real world 0,25 mm.

There can be some lens distortion. Straight lines become curved and rectangles appear as bulged to barrels or pinched to pillows. Small camera lens aperture when taking a photo and software lens distortion compensation minimize it. Manual camera setting is practically a must for best results. Shooting a test image of a perfect checkerboard reveals the lens distortion. That all belongs to photographer's skill set and it's off-topic here.

I cannot see any bulged or pinched shapes in your photo, so the lens distortion can be neglible. A lucky accident? Maybe, but as well the maker of the photo can know what he does. I would do a test shot with the same manual camera settings of a test checkerboard at the same distance. Photo editing programs have manual lens distortion compensation tools for simple distortion forms and at least Photoshop knows numerous popular camera lenses and can compensate the distortion automatically.

Then there's the blue grid - like someone had inserted it afterwards to the photo. Very likely it wasn't there when the photo was shot, so it offers exactly zero information of the target. Opposite: It can cover some details. Hopefully it's not actually inserted to the image, but made by Inkscape when you tinkered there and hoped it could be used during the whole process.

But there's also something very useful: The 90 degrees metal ruler. Hopefully it was in perfect condition when the photo was shot, it was in parallel with the surface and you still have it. It's your bridge over the perspective and scale problems. A perfect rectangle would be even more useful because it would get some redundancy.

Do the next:

  1. Start in a photo editor, like Photoshop or GIMP. Fix the lens distortion at first (no lens distortion visible in your screenshot). Then rotate the image so that the horizontal wing of the ruler becomes horizontal.

  2. Adjust the image perspective in GIMP or Photoshop so that the vertical wing of the ruler becomes exactly vertical(see the note below). Use a perspective transform, do not use skewing nor other distortions!

  3. Stretch the photo either horizontally or vertically so that the ratio of the lengths of the ruler wings in the photo become the same as in the real ruler.

  4. Goto Inkscape and trace the wanted shape of the photo with the Bezier curve tool as accurately as you can with the thinnest curve you can see. Trace also the ruler to have a scale reference in the same image.

NOTE: To stay in truth I must add that if there's no lens distortion Inkscape alone is theoretically enough. You can trace at first the interesting shape and the ruler and make then the needed rotation and perspective corrections. I believe you have already thought this by yourself.

Combine the shape and the ruler paths to be able to insert the perspective envelope path effect. It's possible that your traced version has everything traced right and the image is just waiting for this step.

Drag to the board a couple of guides (the grid can do the same) and adjust the perspective envelope to get the ruler wings to exact 90 degrees. Remember to have "force mirroring" ON.

Convert the result to path to make the perspective correction permanent. Do it before the next step.

Finally stretch the width-height ratio so that it's ok for the metal ruler. Scale to the wanted end-usage dimensions. Break apart to be able to save the shape alone without the ruler.

The numerical user interface of the perspective envelope effect needs practicing. In GIMP and Photoshop the perspective adjustment is visual.

A different approach which doesn't need perspective straightening: Make a 3D model by shooting a mass of photos from different directions with exactly same manual camera settings. Let a photogrammetry program make a 3D model for you.

That's another form of art which needs some knowledge & practicing, but from the resulted 3D model one can measure more things than from a single flat photo.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.