2
$\begingroup$

as shown in Image correlation I would like to detect the shift between a stack of images. Here are the images:

image 1 image 2

and here the code:

{i1, i2} = {Import["https://i.stack.imgur.com/r2QWw.png"], 
 Import["https://i.stack.imgur.com/3NbR9.png"]}
ch = ChanVeseBinarize /@ {i1, i2};
dsc = FillingTransform /@ (DeleteSmallComponents[#, 5] & /@ {ch[[1]], 
  ColorNegate[ch[[2]]]});
pts = ImageCorrespondingPoints[dsc[[1]], dsc[[2]]];
f = FindGeometricTransform[pts[[1]], pts[[2]], 
"Transformation" -> "Translation", Method -> "RANSAC"]
GraphicsGrid@{{i1, 
ImagePerspectiveTransformation[i2, f[[2]], DataRange -> Full]}}

Unfortunately, applying ImageTrim leaves a black line at the edge:

ImageTrim[
 ImagePerspectiveTransformation[i2, f[[2]], 
 DataRange -> Full], {{f[[2, 1, 1, 3]], 
 f[[2, 1, 2, 3]]}, {ImageDimensions[i1][[1]], 
 ImageDimensions[i1][[2]]}}]

trimmed

Does anybody knows a solution for this problem?

$\endgroup$
5
  • $\begingroup$ No black line for me on v8: screenshot. $\endgroup$
    – Öskå
    Jul 27, 2014 at 9:21
  • 2
    $\begingroup$ I confirm the black line in v.10.0.0 and no black line in v.8.0.4 under Win7 x64. $\endgroup$ Jul 27, 2014 at 9:40
  • $\begingroup$ Hmm, I get no corresponding points from ImageCorrespondingPoints in V9.0.1 (Mac) and a thick black line in V8.0.4: i.stack.imgur.com/wQEK7.png $\endgroup$
    – Michael E2
    Jul 27, 2014 at 13:38
  • $\begingroup$ Bug still appears present in version 10.0.1 $\endgroup$
    – Mr.Wizard
    Sep 17, 2014 at 13:57
  • $\begingroup$ bug still present in 10.0.2 $\endgroup$
    – Nasser
    Dec 11, 2014 at 1:05

1 Answer 1

3
$\begingroup$

This should solve the problem:

ImagePad[ImagePerspectiveTransformation[i2, Round[f[[2]][[1]]], 
DataRange -> Full], -BorderDimensions[
ImagePerspectiveTransformation[i2, Round[f[[2]][[1]]], 
DataRange -> Full]]]
$\endgroup$

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.