Job:
I am currently working with an image blending tool. What he does is mix the two images by changing their opacity
My problem:
Here is the first image that is an Xray image.

Here is the second image, which is an optical image.

When I mix these two images, I get this as an output.

As you can see here, my optical image is smaller compared to the xray image. I want my optical image to be perfectly aligned with the xray image.
The code I used:
private BitmapSource processImage (BitmapSource bitm, bool gray)
{
int adaptiveThresholdBlockSize = 4;
double adaptiveThresholdParameter = 1.2d;
int cannyThreshold = 50;
double maxArea_optic;
double maxArea_gray;
System.Drawing.Rectangle rect = new System.Drawing.Rectangle();
Image<Gray, byte> source;
Image<Gray, byte> optical;
MemoryStream outStream = new MemoryStream();
BitmapEncoder enc = new BmpBitmapEncoder();
enc.Frames.Add(BitmapFrame.Create(bitm));
enc.Save(outStream);
var myBmp = new System.Drawing.Bitmap(outStream);
Image<Bgr, byte> sampleImg = new Image<Bgr, byte>(myBmp);
Image<Gray, byte> grayImg = sampleImg.Convert<Gray, byte>();
grayImg = sampleImg.Convert<Gray, byte>().PyrDown().PyrUp();
if (gray)
source = grayImg;
else
optical = grayImg;
grayImg = grayImg.SmoothBlur(10, 10, true);
grayImg = grayImg.SmoothMedian(15);
grayImg = grayImg.SmoothBilatral(7, 255, 34);
grayImg = grayImg.SmoothGaussian(3, 3, 34.3, 45.3);
grayImg._ThresholdBinary(new Gray(100), new Gray(255));
Image<Gray, byte> cannyFrame = grayImg.Canny(new Gray(cannyThreshold), new Gray(cannyThreshold));
CvInvoke.cvAdaptiveThreshold(grayImg, grayImg, 255, Emgu.CV.CvEnum.ADAPTIVE_THRESHOLD_TYPE.CV_ADAPTIVE_THRESH_MEAN_C, Emgu.CV.CvEnum.THRESH.CV_THRESH_BINARY, adaptiveThresholdBlockSize + adaptiveThresholdBlockSize % 2 + 1, adaptiveThresholdParameter);
grayImg._Not();
if (cannyFrame != null)
grayImg._Or(cannyFrame);
Contour<System.Drawing.Point> cont = grayImg.FindContours(Emgu.CV.CvEnum.CHAIN_APPROX_METHOD.CV_CHAIN_APPROX_NONE, Emgu.CV.CvEnum.RETR_TYPE.CV_RETR_LIST);
double[] Area = new double[1000];
double[] width = new double[1000];
double[] height = new double[1000];
int i = 0;
for (Contour<System.Drawing.Point> contour = cont; contour != null; contour = contour.HNext)
{
System.Drawing.Point[] pts = contour.ToArray();
{
Area[i] = (int)contour.Area;
rect = CvInvoke.cvBoundingRect(contour, 1);
width[i] = rect.Width;
height[i] = rect.Height;
grayImg.Draw(rect, new Gray(150), 3);
}
i++;
}
if (gray)
{
maxArea_gray = Area.Max();
int maxAreaIndex_gray = Area.ToList().IndexOf(maxArea_gray);
rect_width_gray = width[maxAreaIndex_gray];
rect_height_gray = height[maxAreaIndex_gray];
}
else
{
maxArea_optic = Area.Max();
int maxAreaIndex_optic = Area.ToList().IndexOf(maxArea_optic);
rect_width_opt = width[maxAreaIndex_optic];
rect_height_opt = height[maxAreaIndex_optic];
grayImg.Resize((int)rect_width_gray, (int)rect_height_gray, Emgu.CV.CvEnum.INTER.CV_INTER_LINEAR);
}
System.Drawing.Bitmap frm = sampleImg.Bitmap;
BitmapSource btm = Convert_toBitSource(frm);
return btm;
}
, EMGUCV, . , , , , .

.
.