image processing - Rectification / unwrapping of a cylindrical object on a picture in matlab -


i'm trying unwrapp cylinder on picture in matlab, need red markers , yellow threads (see picture attached) on 2d-plane in line. have tried few approaches "imtransform" doesn't seem work.

i thinking of adding grid on cylinder know how adjust transformation.

did have same problem? happy ideas of how solve problem.

enter image description here

strictly speaking, cannot done

the imtransform can allow images rectified through projective transform, assumes objects in image lie on planar surface. taking picture of chessboard 2 different angles. see image below.

rectifying chessboard

the reason chessboard can rectified because planar. because cylinder 3d, cannot rectify points.

what can instead

it possible extract subimages cylinder, rectify each subimage, stitch them together.

example

first, subimages selecting points inbetween red dots (shown red o's on image). note bottom 1 arbitrary. then, pick places want red dots end shown (green x's). image subimages

next, rectify each subimage. note red dots lie on green x's.

subim1

first sub image

subim2

second sub-image

subim3

third sub-image

now stitch image together. note now, red dots lie on same line.

stitched image

close all; clear all; clc;  %read image im1 = imread('crctbm.jpg');  %location of red dots x1 = [49; 106; 178; 234]; y1 = [115 116 126 136];  %red dots aligned on yline in final image yline = y1(1);  %initialize cells subim = cell(1,length(x1)-1);       %tracks parsed images transform = cell(1,length(x1)-1);   %projective transform each subim rectifiedim = cell(1,length(x1)-1); %rectified images  %initialize boundaries of image (due warping, images can %stretch beyond border of original image) xdataout = [1,1]; ydataout = [1,1];  t1 = figure; imshow(im1); ii = 1:length(x1)-1     %extract subimage defined red dots     tim = zeros(size(im1));     tim(:,x1(ii):x1(ii+1),:) = im1(:,x1(ii):x1(ii+1),:);     subim{ii} = tim;      %define 4 points in 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 there 4 points should lie in rectified image     correctedpoints{ii} = [x1(ii),yline;... %red dot should stay on same x-coordinate, y-coordinate shited yline         x1(ii+1),yline;...                  %red dot should stay on same x-coordinate, y-coordinate shited yline         x1(ii),yline+50;...                 %rectilinear point         x1(ii+1),yline+50];                 %rectilinear point      %plot original , corrected coordinates on 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 rectified image extends beyond borders of     %original boundary. finds worst case scenario warping ,     %sets boundaries     transform{ii} = maketform('projective',originalpoints{ii},correctedpoints{ii});     [~,xdataim2t,ydataim2t]=imtransform(im1,transform{ii});     % xdataim2t , ydataim2t store bounds of 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 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 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 subimages finalim = zeros(size(rectifiedim{1})); ii = 1:length(rectifiedim)     finalim = max(double(finalim),double(rectifiedim{ii})); end figure; imshow(uint8(finalim)); 

edit:

if care aligning points in 1d, possible align them along epipolar lines.


Comments