如何在四个控制点之间平均裁剪两个图像,然后使用MATLAB将它们相乘?

时间:2019-06-22 20:43:24

标签: matlab

我在两个点​​之间裁剪了两个图像,对它们执行转换后,将它们相乘时会出现这样的错误

[这是第一幅图像和第二幅图像,都是通过移动相机捕获的

这是我为此目的在MATLAB中编写的代码

im_base=imread('C:\Users\khataab\Pictures\practical\kk\base.jpg');

im_base=rgb2gray(im_base);
[b_height,b_width]=size(im_base);
if b_width>b_height
    im_base=imrotate(im_base,-90);
end
im_base=imbinarize(im_base,'adaptive','ForegroundPolarity','dark','Sensitivity',0.4);

n_im_base=not(im_base);
figure,imshow(n_im_base);title('binary base');
% This is second image which is captured by mobile camera
im_sheet=imread('C:\Users\khataab\Pictures\practical\kk\test2.jpg');

im_sheet=rgb2gray(im_sheet);
[t_height,t_width]=size(im_sheet);
if t_width>t_height
    im_sheet=imrotate(im_sheet,-90);
end
im_sheet=imbinarize(im_sheet,'adaptive','ForegroundPolarity','dark','Sensitivity',0.4);

n_im_sheet=not(im_sheet);
figure,imshow(n_im_sheet);title('binary sheet');

% this function remove all small component only leave corners square in
% base image only leave component greater then 10000 of size
base_remove=base_image(n_im_base);
s_base = regionprops(base_remove,'centroid');
fixedPoints=cat(1,s_base.Centroid);
c_base = reshape([s_base.Centroid],2,length(s_base)).';
%crop the image: min(c) will determine xmin and ymin, and max(c)-min(c) will determine the width and height

% this function remove all small component from the test image and only
% leave corners square with size greater then 10000
sheet_remove=sheet_image(n_im_sheet);
s_sheet = regionprops(sheet_remove,'centroid');
monvingPoints=cat(1,s_sheet.Centroid);
c_sheet = reshape([s_sheet.Centroid],2,length(s_sheet)).';
figure,imshow(c_sheet);title('c_sheet');
% this function estimate transformation
mytransform=fitgeotrans(movingPoints,fixedPoints,'similarity');
registered=imwarp(n_im_sheet,mytransform);
%registered=imrotate(registered,-180);
figure,imshowpair(n_im_base,registered,'blend');title('ble');
figure,imshow(registered);title('rgistred');

% These are the point to crop the test image
sheet_cropped = imcrop(registered,[min(c_sheet) max(c_sheet)-min(c_sheet)]);
Sheet_filtered=filtered_sheet(sheet_cropped);
figure,imshow(Sheet_filtered);title('sheet filtered');

% These are the point to crop the base image
Base_cropped = imcrop(n_im_base,[min(c_base) max(c_base)-min(c_base)]);
Base_filtered=filtered_base(Base_cropped);
figure,imshow(Base_filtered);title('base filtered');
%Z = immultiply(X,Y) multiplies each element in array X by the corresponding element in array Y 
%and returns the product in the corresponding element of the output array Z.
Result_Image=immultiply(Base_filtered,Sheet_filtered);

%[L,num] = bwlabel(___) also returns num, the number of connected objects found in BW.
[L,count]=bwlabel(Result_Image);
figure,imshow(Result_Image);

我想将最后的两个图像相乘sheet_filtered和base_filtered,但是给我这样的错误

Error using immultiply>doLogicalMultiplication (line 65)
X and Y must be the same size.

Error in immultiply (line 46)
    Z = doLogicalMultiplication(X,Y);

Error in step1 (line 70)
Result_Image=immultiply(Base_filtered,Sheet_filtered);

这是精简代码,抱歉,我不能再精简代码

%sheet_remove is a function which eliminate all small element and leave
%only four square in the corners
s_sheet = regionprops(sheet_remove,'centroid');
monvingPoints=cat(1,s_sheet.Centroid);
c_sheet = reshape([s_sheet.Centroid],2,length(s_sheet)).';
%Centroid of four quare on base image
base_remove=base_image(n_im_base);
s_base = regionprops(base_remove,'centroid');
fixedPoints=cat(1,s_base.Centroid);
c_base = reshape([s_base.Centroid],2,length(s_base)).';

mytransform=fitgeotrans(movingPoints,fixedPoints,'similarity');
registered=imwarp(n_im_sheet,mytransform);

sheet_cropped = imcrop(registered,[min(c_sheet) max(c_sheet)-min(c_sheet)]);
%filtered_sheet is a function which filter images from noise
Sheet_filtered=filtered_sheet(sheet_cropped);

Base_cropped = imcrop(n_im_base,[min(c_base) max(c_base)-min(c_base)]);
Base_filtered=filtered_base(Base_cropped);

Result_Image=immultiply(Base_filtered,Sheet_filtered);

这是移动相机捕获的第一张图像和第二张图像,如下所示: imagine

0 个答案:

没有答案