1直接拼接,去两张图,直接拼接,适用于没有变形的,分割的图像复原整个图像.
read_image (Image, ‘1.bmp’)
dev_close_window ()
dev_open_window_fit_image (Image, 0, 0, -1, -1, WindowHandle)
dev_display (Image)
read_image (Image1, ‘2.bmp’)
dev_close_window ()
dev_open_window_fit_image (Image1, 0, 0, -1, -1, WindowHandle1)
dev_display (Image1)
concat_obj (Image, Image1, ObjectsConcat)
tile_images (ObjectsConcat, TiledImage, 1, ‘vertical’)
dev_close_window ()
dev_open_window_fit_image (TiledImage, 0, 0, -1, -1, WindowHandle2)
dev_display (TiledImage)
stop ()
get_image_size (Image1, Width, Height)
concat_obj (Image, Image1, ObjectsConcat1)//拼接宽度Rowoffset,高度,其它参数 默认
tile_images_offset (ObjectsConcat1, TiledImage1, [0,Height], [0,0], [-1,-1], [-1,-1], [-1,-1], [-1,-1], Width, Height*2)
dev_close_window ()
dev_open_window_fit_image (TiledImage1, 0, 0, -1, -1, WindowHandle2)
dev_display (TiledImage1)
stop ()
2第二种模版匹配的拼接,需要找到两张图的共同区域,然后进行拼接.,感兴趣的自己找两张同样大小的图片测试看看.
dev_update_window (‘off’)
dev_close_window ()
dev_open_window (0, 0, 640, 480, ‘white’, WindowHandle)
dev_set_color (‘green’)
set_display_font (WindowHandle, 14, ‘mono’, ‘true’, ‘false’)
gen_empty_obj (Images)
width:=[]
height:=[]
*设置图片的路径(需要修改)
list_files (‘…//pi’, [‘files’,‘follow_links’], ImageFiles)
tuple_regexp_select (ImageFiles, [‘\.(tif|tiff|gif|bmp|jpg|jpeg|jp2|png|pcx|pgm|ppm|pbm|xwd|ima|hobj) ′ , ′ i g n o r e c a s e ′ ] , I m a g e F i l e s ) f o r J : = 0 t o ∣ I m a g e F i l e s ∣ − 1 b y 1 r e a d i m a g e ( I m a g e , I m a g e F i l e s [ J ] ) g e t i m a g e s i z e ( I m a g e , W i d t h , H e i g h t ) w i d t h : = [ w i d t h , W i d t h ] h e i g h t : = [ h e i g h t , H e i g h t ] c o n c a t o b j ( I m a g e s , I m a g e , I m a g e s ) d e v d i s p l a y ( I m a g e ) d i s p m e s s a g e ( W i n d o w H a n d l e , ′ I m a g e ′ + J ','ignore_case'], ImageFiles) for J := 0 to |ImageFiles|-1 by 1 read_image (Image, ImageFiles[J]) get_image_size (Image, Width, Height) width:=[width,Width] height:=[height,Height] concat_obj (Images, Image, Images) dev_display (Image) disp_message (WindowHandle, 'Image ' + J ′,′ignorecase′],ImageFiles)forJ:=0to∣ImageFiles∣−1by1readimage(Image,ImageFiles[J])getimagesize(Image,Width,Height)width:=[width,Width]height:=[height,Height]concatobj(Images,Image,Images)devdisplay(Image)dispmessage(WindowHandle,′Image′+J’d’, ‘image’, -1, -1, ‘black’, ‘true’)
wait_seconds (1)
endfor
disp_continue_message (WindowHandle, ‘black’, ‘true’)
stop ()
maxHeight:=sum(height)
*设置合成列坐标(需要修改) 三张图用这个
set_display_font (WindowHandle1, 16, ‘mono’, ‘true’, ‘false’)
for J := 0 to Num-1 by 1
F := From[J]
T := To[J]
select_obj (Images, ImageF, F)
get_image_size (ImageF, Width1, Height1)
dev_set_window_extents (-1, -1, Width1, Height1)
dev_display (ImageF)
disp_message (WindowHandle1, ‘绘制出第’+F+‘张图片与第’+T+‘张图片的重叠区域’, ‘window’, 0, 0, ‘black’, ‘true’)
*绘制要搜索的区域ImageF
draw_rectangle1 (WindowHandle1, Row1, Column1, Row2, Column2)
gen_rectangle1 (RectangleF, Row1, Column1, Row2, Column2)
select_obj (Images, ImageT, T)
get_image_size (ImageT, Width1, Height1)
dev_set_window_extents (-1, -1, Width1, Height1)
dev_display (ImageT)
disp_message (WindowHandle1, '绘制出第'+T+'张图片与第'+F+'张图片的重叠区域', 'window', 0, 0, 'black', 'true')
*绘制要搜索的区域ImageT
draw_rectangle1 (WindowHandle1, Row1, Column1, Row2, Column2)
gen_rectangle1 (RectangleT, Row1, Column1, Row2, Column2)
reduce_domain (ImageF, RectangleF, ImageFF)
reduce_domain (ImageT, RectangleT, ImageTT)
*获取图片信息
points_foerstner (ImageFF, 1, 2, 3, 200, 0.1, 'gauss', 'false', RowJunctionsF, ColJunctionsF, CoRRJunctionsF, CoRCJunctionsF, CoCCJunctionsF, RowAreaF, ColAreaF, CoRRAreaF, CoRCAreaF, CoCCAreaF)
points_foerstner (ImageTT, 1, 2, 3, 200, 0.1, 'gauss', 'false', RowJunctionsT, ColJunctionsT, CoRRJunctionsT, CoRCJunctionsT, CoCCJunctionsT, RowAreaT, ColAreaT, CoRRAreaT, CoRCAreaT, CoCCAreaT)
*对比图片信息
*通过查找点之间的对应关系来计算两个图像之间的投影变换矩阵
*参数一 输入图像1
*参数二 输入图像2
*参数三 输入的图像1中特征点的行坐标
*参数四 输入的图像1中特征点的列坐标
*参数五 输入的图想2中特征点的行坐标
*参数六 输入的图像2中特征点的列坐标
*参数七 输入的灰度值比较指标
*参数八 输入的灰度值蒙版的大小
*参数九 输入的平均行坐标偏移
*参数十 输入的平均列坐标偏移
*参数十一 输入的匹配搜索窗口的一半高度
*参数十二 输入的匹配搜索窗口的一半宽度
*参数十三 输入的旋转角度范围
*参数十四 输入的灰度值匹配的阈值
*参数十五 输入的变换矩阵估计算法
*参数十六 输入的转换一致性检查的阈值
*参数十七 输入的随机数生成器的种子
*参数十八 输出的均匀投影变换矩阵
*参数十九 输出的图像1中匹配的输入点的索引
*参数二十 输出的图像2中匹配的输入点的索引
* 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
proj_match_points_ransac (ImageF, ImageT, RowJunctionsF, ColJunctionsF, RowJunctionsT, ColJunctionsT, 'ncc', 15, 0, 0, width[0],width[0], 0, 0.5, 'gold_standard', 2, 45, ProjMatrix, Points1, Points2)
ProjMatrices := [ProjMatrices,ProjMatrix]
Rows1 := [Rows1,subset(RowJunctionsF,Points1)]
Cols1 := [Cols1,subset(ColJunctionsF,Points1)]
Rows2 := [Rows2,subset(RowJunctionsT,Points2)]
Cols2 := [Cols2,subset(ColJunctionsT,Points2)]
NumMatches := [NumMatches,|Points1|]
gen_cross_contour_xld (PointsF, RowJunctionsF + height[(F - 1)], ColJunctionsF, 6, rad(45))
gen_cross_contour_xld (PointsT, RowJunctionsT + height[(T - 1)], ColJunctionsT, 6, rad(45))
RowF := subset(RowJunctionsF,Points1) + height[(F - 1)]
ColF := subset(ColJunctionsF,Points1)
RowT := subset(RowJunctionsT,Points2) + height[(T - 1)]
ColT := subset(ColJunctionsT,Points2)
gen_empty_obj (Matches)
for K := 0 to |RowF| - 1 by 1
gen_contour_polygon_xld (Match, [RowF[K],RowT[K]], [ColF[K],ColT[K]])
concat_obj (Matches, Match, Matches)
endfor
dev_set_color ('blue')
dev_display (Matches)
dev_set_color ('green')
dev_display (PointsF)
dev_display (PointsT)
wait_seconds (1)
endfor
gen_projective_mosaic (Images, MosaicImage, 2, From, To, ProjMatrices, ‘default’, ‘false’, MosaicMatrices2D)
dev_close_window ()
dev_open_window_fit_image (MosaicImage, 0, 0, -1, -1, WindowHandle2)
dev_display (MosaicImage)
get_image_size (MosaicImage, Width2, Height2)