Tool for Stretching/Scaling Multiple Selections by Their Vertexes?

I have a large scan of a picture with multiple folds in it. I need a tool that will let me take each folded section of the picture and stretch/scale it along its vertexes such that I can shape each folded section to fill in the boundaries of the canvas. I’ve already rotated and cropped the picture as much as possible, however scanned pictures never seem to be perfectly rectangular.

Using both GIMP 2.10.34 and GIMP 2.99.16, I’ve attempted using the perspective tool, but discovered that when manipulating a vertex, it will warp/modify pixels along non-adjacent edges, making lines that go through the picture’s folded section look very noticeably misaligned, with no obvious options to keep it from doing this.

For instance, let’s say I have a picture with a single fold. The right half is perfectly aligned and square to the canvas, filling it up to the edge. The left half, however, has its left edge not perfectly aligned to the canvas. The top left corner needs to be pushed to the left by a few dozen pixels, so I use the perspective tool to do that. However, now the right edge has been modified. The pixels on the right edge, specifically the middle of the right edge, are now pushed down by a dozen or so pixels. So any lines that cross over the right edge of the left fold are now misaligned with the left edge of the right fold.

I’ve attempted to do the same thing with multiple other tools. The scale tool will only do edges, so that won’t work. Trying to do a handle transform with four points on the fold’s vertexes gives the same perspective transform, as does using the unified transform tool. I’ve also tried using the cage transform with four points positioned on the fold’s vertexes, but the tool just seems to fail for this use case with a large selection that needs precise manipulation as, when deforming points, the points do not follow the vertexes, which is compounded by the fact that there is no preview option, so the results for any adjustment have me waiting for 15 or so seconds for the tool to do its thing, after which I end up having to nudge it multiple times, and when a vertex is finally nudged into place, the other vertexes and edges of the selection end up screwed up in weird ways, such as other vertexes moving when they weren’t touched or a row/column of half a dozen pixels doubling/repeating themselves along the edges.

Basically, what I need is a tool that gives me vertex manipulation that’s similar to the perspective tool, but with results more akin to the scale tool if the scale tool also had vertex support so that the lines that go through the middle of my scanned folded picture don’t end up misaligned by the end of it.

Did you tried the Unified Transform Tool in Corrective mode?

https://docs.gimp.org/2.10/en/gimp-tool-unified-transform.html

Giving us an example or an excerpt of your image would have been worth 500 words, I was hopping for a TL;DR somewhere in your text (It’s the morning for me, I did not finish my first coffee, I got a bit lost) :wink:

1 Like

I think I’ve got an ingenious/dead simple solution to this, but it’s getting late, so I’ll post it tomorrow. In the meantime, here’s a quick, somewhat exaggerated image showing my problem.

While making this, I realized that my desired tool would result in different angles for the lines going through the middle edge, even if they did line up. Edit: In retrospect, any solution would have done this.

Anyways, solution tomorrow.

1 Like

For this example, we want to have a scanned, previously folded picture cover as much of the canvas as possible while cropping out as little as possible. This way, we end up with the edges of the picture as close to the edges of the canvas as possible. This could be useful, for example, for pictures with very detailed edging.

To start with, here’s a simple and exaggerated example of what a scanned folded picture might look like once the crease has been vertically aligned and the canvas has been cropped to the edges of the picture. The white is the picture, the red lines are to show alignment, the black line is the crease, and the blue is the part of the canvas the picture isn’t overlapping.

  1. Select the left half of the image using the Rectangle Select Tool and select all the way to the middle of the crease.
  2. Select the Perspective Tool and click on the selection.
  3. In the tool options, select the options “Corrective (Backward)” and “Constrain handles” (For this example, I also use NoHalo Interpolation).
  4. Drag the corners up or down to have them meet the corners of the picture. Make sure to ONLY drag them VERTICALLY for this step. Do not drag the corners horizontally, or the red lines will become misaligned. The Show preview image option in the Tool Options can show what transformations will be done to the image.
  5. Hit the enter key or select the Transform option to lock in the results.
  6. Repeat steps 1-5 (more or less) for the right half of the image. Transformations may need to be set to new layers with ctrl+shift+n. Make sure the layer to be modified is the current working layer.

Doing this should give the below image:

We’re not done yet, but notice that the lines are aligned between the left and right halves. It looks like there might be a slight angle offset/skewing between the two lines, but to get our results this is probably a necessary trade-off. Next steps:

  1. Select the whole image. This can be done by double-clicking with the Rectangle Select Tool. The entire image may need to be merged first. Do ctrl+m, use the defaults, and select merge to do this.
  2. Select the Perspective Tool and click on the selection.
  3. In the Tool Options, select the options “Corrective (Backward)” and “Constrain handles”. (For this example, I also use NoHalo Interpolation).
  4. Drag the corners and have them meet the corners of the picture. Since all the vertical alignment has already been done, only horizontal alignment should be necessary for this step.
  5. Hit the enter key or select the Transform option to lock in the results.

Doing this should give the below image:

As can be seen, the edges of our picture now meet the edges of our canvas while the lines going through the middle of it are still aligned. The tradeoff is that the image is now slightly skewed as can be seen by our black crease no longer being perfectly vertical and the lines going through the middle slightly change their angle. However, real images will generally need much less perspective transform and will have much more going on for such downsides to be all that noticeable.