I guess my last post is at least an outline of an answer to you question. What did you try? Where is you code? Regards -- Henrik
|
|
Well, I then understand your problem in not having a reference image. Maybe you can solve it like this (I am now working with the skewed image only!):
- I first cropped the image to avoid any frame/axis in the image; as a compensation a small image pad is used (with an appropriate image acquisition this should not be necessary):
then I made kind of a mask of the image and detected the corners:
(* setting all blue background pixel to black, then binarize: *)
bckgrnd = {0.596078431372549`, 0.7686274509803922`,
0.9137254901960784`};
imgskd1 =
Binarize[ColorConvert[
ImageApply[If[# == bckgrnd, {0, 0, 0}, #] &, imgskd0],
"Grayscale"], 0.001];
ipoints = ImageCorners[imgskd1, MaxFeatures -> w[imgskd1, Graphics[{PointSize[.05], Red, Point /@ ipoints}]]
finally one has to bring these points in a defined order so that they can be associated with reference points:
(* ordering these points in a counterclock fashion: *)
middle = Mean[ipoints];
posVec = # - middle & /@ ipoints;
order = Ordering[ArcTan @@@ posVec];
opoints = ipoints[[order]];
(* defining reference points in the same order: *)
refpoints = {{0, 0}, {500, 0}, {500, 500}, {0, 500}};
(* ... and performing the correction *)
gtf = Last@FindGeometricTransform[refpoints, opoints];
ImagePerspectiveTransformation[imgskd, gtf, DataRange -> Full]
The result is: Regards -- Henrik
|
|
Dear Henrik, very nice solution indeed! Best wishes, Marco
|
|
Dear Marco, thanks a lot for your nice compliment! Best wishes -- Henrik
|
|
Really nice. The only thing I can suggest is, for purposes of working with hardware that does not have Mathematica, possibly a singular values decomposition can be useful. This is implemented in Lapack and so is available on many platforms. What I cannot say, unfortunately, is how best to apply it to the problem at hand (a bit too far from my expertise). But I'm pretty sure some form of SVD, on normalized pixel values or perhaps on a matrix given by the "corner" positions, should be applicable for finding the appropriate sheer.
|
|
Wow. Thanks Henrik! That looks really good. I will not be able to run this in mathematica so it is important that I determine a general algorithm for unskewing the image. Thanks again mrphud
|
|
I will not be able to run this in mathematica ...
Well, I am assuming that you have at least some access to Mathematica, because you are posting on the Wolfram community platform! This way you can get the information for your specific image correction, which can be used by some other program you are doing the actual correction with. Regards -- Henrik
|
|
Henrik, Thank you for showing how to extract the parts of TransformationFunction which correspond to translation and linear transformation. Could you please also explain how to deal with the bottom line of the TransformationFunction 's matrix?
|
|
Hi Alexey, I do not have any idea about the meaning of this bottom line! Actually before I posted the above "explanation" I made a search in the documentation and on StackExchange, but I could not find anything; so I was hoping I could get away without being asked that obvious question. I would like to know it myself! Surely someone from this community can help ... Regards -- Henrik
|
|
Hi Cole, the function FindGeometricTransform seems to be perfect for this task; with ImagePerspectiveTransformation the resulting transformation can then be applied:
imgskd = Import["skewed.png"];
imgcor = Import["corrected.png"];
gtf = Last@FindGeometricTransform[imgcor, imgskd];
ImagePerspectiveTransformation[imgskd, gtf, DataRange -> Full]
The outcome looks like this: This is just a quick "proof of concept"; for better results you should crop you images properly. Regards -- Henrik
|
|
UPDATE: So I found something called shear mapping. This seems to be exactly what I need to apply, but because I am starting with a sheared image in both x and y there is coupling between the axes. I have tried a while loop that iterates the shearing operation in both x and y until its "gone" but it feels like this has to be a known problem.
|
|
Reply to this discussion
in reply to
Group Abstract
|