2

Two cameras takes two images of a wooden plank. The images have an overlap of the plank which I need to stitch together in a way that it looks natural and preferably seamless to the human eye for inspection purposes. The images are cropped to the same size and masked to remove the background and most of the non-overlapping areas but the plank can have a slight tilt on the conveyor belt.

Currently I'm using the normxcorr2 function on the general overlay area, following ideas from the Matlab totorial of the normxcorr2 function, to try and identify one of the images in the other and work out an overlay offset, following the tutorial. However, this fails quite often as the normxcorr2 functions returns a zero offset - resulting in a bad stitching:

c = normxcorr2(plank_part1,plank_part2);

Find peak in cross-correlation:

[ypeak, xpeak] = ind(c==max(c(:)));

Account for the padding that normxcorr2 adds:

yoffSet = ypeak-size(onion,1);
xoffSet = xpeak-size(onion,2);

[xoffSet,yoffSet]

ans =

0     0

It would seem normxcorr2 can not always find the correct overlay of the images, or any overlay at all(?), even though I try to make it easier by increasing the gray scale contrast by the function histeq. My guess is that the amount of "gray-ish" area from the sapwood overwhelms the distinct knots, which are the important parts to stitch propperly.

Simple gray scale example

High contrast example

Does anyone know of a way to either increase the likelihood of this stitching process, maybe by some more preprocessing, or use any other matlab skills/functions to make this work better?

P.S I can not use anything but freely accessible scripts as this would probably become license/copyright issues for my project.

Thank you for your time in trying to help!

Ander Biguri
  • 35,140
  • 11
  • 74
  • 120
  • The white border is made by matlab. If you need help perhaps you need to post the images themselves. However, You are not going to stitch using correlation, as those planks are definitely not one after the other. they dont visually stitch – Ander Biguri Aug 17 '17 at 14:33
  • Don't use histeq as a preprocessing, it is a non-linear transform and will definitely kill any correlation, if there is some. Please update your question and post two original images for which your code fails. – Ratbert Aug 17 '17 at 15:19

1 Answers1

2

You should look at the following link. The term that you should be looking for is image registration. There are more advanced methods than normxcorr2

MosGeo
  • 1,012
  • 9
  • 9
  • Very good link to a new term for me, thanks! P.S I've yet to get any of the suggested methods from that link to work yet but you've sent me into a new direction of opportunities! – Linus Olofsson Aug 21 '17 at 05:47
  • 1
    You might also want to check out Fiji: ImageJ for fast prototyping and testing (https://imagej.net/Category:Registration). The software is free and open source. A lot of new algorithms are implemented for registration. – MosGeo Aug 21 '17 at 18:07
  • Thanks for the tip, I've heard good things about imagej already. However I need to do this in Matlab. FYI, I will probably be using Matlab's 'step' function of the vision package, for template matching, but I would not have found this method without your help, thanks! – Linus Olofsson Aug 23 '17 at 06:29
  • I do everything in Matlab too. I just find ImageJ and Fiji to be a good tool to experiment with. Only one time where I actually wrote a matlab scripts that calls the ImageJ functions and get the results from there. – MosGeo Aug 23 '17 at 14:28