温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

怎么在python中利用numpy 显示图像阵列

发布时间:2021-05-02 14:16:12 来源:亿速云 阅读:221 作者:Leah 栏目:开发技术

怎么在python中利用numpy 显示图像阵列?相信很多没有经验的人对此束手无策,为此本文总结了问题出现的原因和解决方法,通过这篇文章希望你能解决这个问题。

python的五大特点是什么

python的五大特点:1.简单易学,开发程序时,专注的是解决问题,而不是搞明白语言本身。2.面向对象,与其他主要的语言如C++和Java相比, Python以一种非常强大又简单的方式实现面向对象编程。3.可移植性,Python程序无需修改就可以在各种平台上运行。4.解释性,Python语言写的程序不需要编译成二进制代码,可以直接从源代码运行程序。5.开源,Python是 FLOSS(自由/开放源码软件)之一。

1、输入图像列表 img_list

2、show_type : 最终的显示方式,输入为行数列数 (例如 show_type=22 ,则最终显示图片为两行两列)

3、basic_shape, 图片resize的尺寸。

def image_show( img_list, show_type, basic_size=[300,500]):
 '''
  img_list contains the images that need to be stitched,
  the show_typ contains the final shape of the stitched one, ie, 12 for 1 row 2 cols.
  basic_size : all input image need to be reshaped first. 
 
 '''
 # reshap row and col number. 
 n_row, n_col = basic_size
 #print n_row,n_col
 
 # num of pixels need to be filled vertically and horizontally.
 h_filling = 10
 v_filling = 10
 
 
 # image resize. 
 resize_list=[]
 for i in img_list:
  temp_img = cv2.resize( i, ( n_col, n_row ), interpolation = cv2. INTER_CUBIC )
  resize_list.append( temp_img )
 
 # resolve the final stitched image 's shape.
 n_row_img, n_col_img = show_type/10, show_type%10
 #print n_row_img, n_col_img
 
 # the blank_img and the image need to be filled should be defined firstly.
 blank_img= np.ones([n_row,n_col])*255
 blank_img= np.array( blank_img, np.uint8 )
 v_img= np.array( np.ones([n_row,v_filling])*255, np.uint8)
 h_img= np.array( np.ones ([ h_filling, n_col_img*n_col+(n_col_img-1)*h_filling])*255, np.uint8)
 
  
 # images in the image list should be dispatched into different sub-list
 # in each sub list the images will be connected horizontally.
 recombination_list=[]
 temp_list=[]
 n_list= len(resize_list)
 for index, i in enumerate ( xrange (n_list)):
  if index!= 0 and index % n_col_img==0 :
   recombination_list.append(temp_list)
   temp_list = []
   if len(resize_list)> n_col_img:
    pass
   else:
    recombination_list.append(resize_list)
    break
  temp_list.append( resize_list.pop(0))
 if n_list== n_col_img:
  recombination_list.append(temp_list)
 #print len(temp_list)
 #print temp_list
 
 
 # stack the images horizontally.
 h_temp=[]
 for i in recombination_list:
  #print len(i)
  if len(i)==n_col_img:
   
   temp_new_i=[ [j,v_img] if index+1 != len(i) else j for index, j in enumerate (i) ]
   new_i=[ j for i in temp_new_i[:-1] for j in i ]
   new_i.append( temp_new_i[-1])
   h_temp.append(np.hstack(new_i))
  else:
   
   add_n= n_col_img - len(i)
   for k in range(add_n):
    i.append(blank_img)
    
   temp_new_i=[ [j,v_img] if index+1 != len(i) else j for index, j in enumerate (i) ]
   new_i=[ j for i in temp_new_i[:-1] for j in i ]
   new_i.append( temp_new_i[-1])
   
   h_temp.append(np.hstack(new_i))
   
   
 #print len(h_temp)
 #print h_temp
   
 temp_full_img= [ [j, h_img ] if index+1 != len(h_temp) else j for index, j in enumerate(h_temp) ]
 if len(temp_full_img) > 2:
  full_img= [ j for i in temp_full_img[:-1] for j in i ]
  full_img.append(temp_full_img[-1])
 else:
  full_img= [ j for i in temp_full_img for j in i ]
  #full_img.append(temp_full_img[-1])
  
 
 
 if len(full_img)>1:
  return np.vstack( full_img) 
 else:
  return full_img

看完上述内容,你们掌握怎么在python中利用numpy 显示图像阵列的方法了吗?如果还想学到更多技能或想了解更多相关内容,欢迎关注亿速云行业资讯频道,感谢各位的阅读!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI