Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
matlab中柱面物体在图像上的校正/展开_Matlab_Image Processing - Fatal编程技术网

matlab中柱面物体在图像上的校正/展开

matlab中柱面物体在图像上的校正/展开,matlab,image-processing,Matlab,Image Processing,我试图在matlab中打开图片上的圆柱体,因为我需要红色标记和黄色线(见附图)在二维平面上对齐。我尝试了一些使用“imtransform”的方法,但似乎不起作用 我还考虑在圆柱体上添加一个网格,以便知道如何调整变换 有人有同样的问题吗?我很乐意得到一些关于如何解决这个问题的想法 严格地说,这是不可能做到的 imtransform允许通过投影变换对图像进行校正,但这假定图像中的对象位于平面上。这就像从两个不同的角度拍摄棋盘。见下图 棋盘可以被修正的唯一原因是因为它是平面的。由于圆柱体是三维的,因

我试图在matlab中打开图片上的圆柱体,因为我需要红色标记和黄色线(见附图)在二维平面上对齐。我尝试了一些使用“imtransform”的方法,但似乎不起作用

我还考虑在圆柱体上添加一个网格,以便知道如何调整变换

有人有同样的问题吗?我很乐意得到一些关于如何解决这个问题的想法


严格地说,这是不可能做到的

imtransform允许通过投影变换对图像进行校正,但这假定图像中的对象位于平面上。这就像从两个不同的角度拍摄棋盘。见下图

棋盘可以被修正的唯一原因是因为它是平面的。由于圆柱体是三维的,因此无法校正这些点

你可以做些什么

可以从圆柱体中提取子图像,校正每个子图像,然后将它们重新缝合在一起

示例

首先,通过选择红点之间的点(在图像上显示为红色o)获得子图像。请注意,底部的一个是任意的。然后,选择您希望这些红点最终显示为(绿色x)的位置。

接下来,校正每个子图像。请注意,红色圆点现在位于绿色x上

第一子图像

第二副图像

第三副图像

现在将图像重新缝合在一起。请注意,现在所有的红点都位于同一条线上

编辑:


如果您只关心在1D中对齐点,那么也可以沿极线对齐它们

“我尝试了一些使用“imtransform”的方法,但似乎不起作用。”我一直在想。。。它不工作是因为它会出错,或者可能会导致蓝屏死亡,甚至可能是计算机完全爆炸成百万碎片。谁知道呢。这是一个好主意@ceiltechbladhm,也谢谢你的解释。imtransform完全正确,我将用更多的红点尝试这种方法。
close all; clear all; clc;

%Read image
im1 = imread('crCTbm.jpg');

%Location of your red dots
x1 = [49; 106; 178; 234];
y1 = [115 116 126 136];

%Red dots will be aligned on yline in the final image
yline = y1(1);

%Initialize cells
subim = cell(1,length(x1)-1);       %Tracks parsed images
Transform = cell(1,length(x1)-1);   %Projective transform for each subim
RectifiedIm = cell(1,length(x1)-1); %Rectified images

%Initialize boundaries of image (Due to warping, sometimes the images can
%stretch beyond the border of the original image)
xdataout = [1,1]; ydataout = [1,1];

t1 = figure; imshow(im1);
for ii = 1:length(x1)-1
    %Extract a subimage defined by your red dots
    tim = zeros(size(im1));
    tim(:,x1(ii):x1(ii+1),:) = im1(:,x1(ii):x1(ii+1),:);
    subim{ii} = tim;

    %Define four points in the original image
    originalpoints{ii} = [x1(ii),y1(ii);... %Red Dot
        x1(ii+1),y1(ii+1);...               %Red Dot
        x1(ii),y1(ii)+50;...                %Arbitrary point
        x1(ii+1),y1(ii)+50];                %Arbitrary point

    %Define where there four points should lie in the rectified image
    correctedpoints{ii} = [x1(ii),yline;... %Red dot should stay on the same x-coordinate, but y-coordinate is shited to the yline
        x1(ii+1),yline;...                  %Red dot should stay on the same x-coordinate, but y-coordinate is shited to the yline
        x1(ii),yline+50;...                 %Rectilinear point
        x1(ii+1),yline+50];                 %Rectilinear point

    %Plot the original and corrected coordinates on the image
    figure(t1); hold on;
    plot(originalpoints{ii}(:,1),originalpoints{ii}(:,2),'ro');
    plot(correctedpoints{ii}(:,1),correctedpoints{ii}(:,2),'gx');
    legend('Original Points','correctedpoints{ii}');

    %Sometimes the rectified image extends beyond the borders of the
    %original boundary. This finds the worst case scenario for warping and
    %sets the boundaries to that
    Transform{ii} = maketform('projective',originalpoints{ii},correctedpoints{ii});
    [~,xdataim2t,ydataim2t]=imtransform(im1,Transform{ii});
    % now xdataim2t and ydataim2t store the bounds of the transformed im2
    xdataout=[min([1,xdataim2t(1),xdataout(1)]) max([size(im1,2),xdataim2t(2),xdataout(2)])];
    ydataout=[min([1,ydataim2t(1),xdataout(1)]) max([size(im1,1),ydataim2t(2),xdataout(2)])];
end

%Rectify the images
rectifiedx = floor(xdataout(1)):ceil(xdataout(2))+1;    %x-coordinates of new image
rectifiedy = floor(ydataout(1)):ceil(ydataout(2))+1;    %y-coordinates of new image
for ii = 1:length(x1)-1
    RectifiedIm{ii}=imtransform(subim{ii},Transform{ii},'XData',xdataout,'YData',ydataout);
    figure; image(rectifiedx,rectifiedy,uint8(RectifiedIm{ii})); hold on;
    plot(originalpoints{ii}(:,1),originalpoints{ii}(:,2),'ro');
    plot(correctedpoints{ii}(:,1),correctedpoints{ii}(:,2),'gx');
    legend('Original Points','Rectified Points');
end

%Stitch the subimages together
finalim = zeros(size(RectifiedIm{1}));
for ii = 1:length(RectifiedIm)
    finalim = max(double(finalim),double(RectifiedIm{ii}));
end
figure; imshow(uint8(finalim));