-1

How is it possible to achieve something similar to this result? Not talking about the contrast and color, but the way the lines are corrected and straight.

This examples were taken from an iOS app

Original Edited

I already tried to use CIPerspectiveCorrection and CIPerspectiveTransform and other kind of filters but without any luck on straightening the lines.

My result with CIPerspectiveCorrection:

My Result

  • Yeah, I think the perspective correction in Core Image handles parallax distortion, where straight lines are still straight but skewed. I don't know of any off-the-shelf solution for the sort of curved distortion you describe. It is a fairly tricky problem. – Duncan C Apr 21 '23 at 16:19
  • I wonder if It would be possible to get such a correction by using the image Depth and then normalize the data to get a "flat" result. – xKore Evolution Apr 24 '23 at 07:26

1 Answers1

1

There are multiple steps here. But what you are asking about is the perspective correction, that is (in photoshop terms) "drag" top corner of the image in direction up and out (to increase its size, and thus make it more proportionate to the rest of the page). With Apple frameworks there are several ways to do perspective correction, but most obvious is CIPerspectiveCorrection (here's an example on how it works).

Now how do you arrive at the conclusion that you need such correction (and which corner(s) need it) is a more interesting topic.

  • one option is that user decides so.
  • another option is to use Vision framework to detect a shape (rectangle), and do the correction based on the distortion of the rectangle. This is not error prone option, but that's what many apps are using.
timbre timbre
  • 12,648
  • 10
  • 46
  • 77
  • I'm already using CIPerspectiveCorrection with Vision framework to detect the rectangles, however, you can see the result that I'm getting with a curved line because the book is curved (I edited my question). I was just wondering how I could improve my result by straightening the document like they do. – xKore Evolution Apr 24 '23 at 07:21
  • I don't think CIPerspectiveCorrection is going to help in this case. That lets you correct for parallax distortion. This is a more complex curved distortion. – Duncan C Apr 24 '23 at 13:26
  • @xKoreEvolution So you completely changed the question... But like I said, this is going to be very situation specific, and you cannot apply the same thing to every image. Your first page (or any page which is straight, but on the angle) definitely needs a perspective correction. In case of your second page - it's a completely different issue, you need to "push down" the top edge of the page somewhere near the start of the curve. And for that any 4-coordinate filter won't be enough. You need a "dewarping" - that is a custom filter which operates on 5 (or possibly even more) points. – timbre timbre Apr 24 '23 at 13:56
  • In short: there's no The Filter that will do it for you. But if you are serious about it, I suggest reading some paper, which explains which types of transformation a paper may need, and how to do them (regardless of tech used). For example this: http://www.cs.cmu.edu/~ILIM/projects/IM/document_rectification/cvpr2011_YuandongTian.pdf – timbre timbre Apr 24 '23 at 14:02
  • @DuncanC In second case - no, and no other single filter will help there. The question was changed from what I answered to. – timbre timbre Apr 24 '23 at 14:02
  • I'll definitely take a look into that, thanks! @klangfarb – xKore Evolution Apr 24 '23 at 15:05