• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

matlab 将图像切分为N*N像素的小块 - 面朝终南山

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

matlab 将图像切分为N*N像素的小块

将数据数据按照N*N的方格切割,并将图像数据输出。
图像不足的部分全部补为0。
图像以cell单元的方式输出,其排列顺序与原图的排向顺序相同。

function Divided_image = Divide_into_N_block(N)
%Brian%2012-10-06% %将数据数据按照N*N的方格切割,并将图像数据输出。 %图像不足的部分全部补为0。 %图像以cell单元的方式输出,其排列顺序与原图的排向顺序相同。 Img = imread(\'im1.png\'); % Img = rgb2gray(Img); [Img_hang , Img_lie] = size(Img); Remainder_hang = rem(Img_hang,N); Remainder_lie = rem(Img_lie,N); Supplement_hang = N - Remainder_hang; Supplement_lie = N - Remainder_lie; if (Remainder_hang > 0 ) hang_flag = 0; else hang_flag =1; end if (Remainder_lie>0 ) lie_flag = 0; else lie_flag =1; end Divided_image = divide_Image(Img,hang_flag,lie_flag,N,Img_hang,Img_lie,Supplement_hang,Supplement_lie); end function Divided_image = divide_Image(Img,hang_flag,lie_flag,N,Img_hang,Img_lie,Supplement_hang,Supplement_lie) [Img_hang , Img_lie] = size(Img); Integer_hang = floor(Img_hang/N); Integer_lie = floor(Img_lie/N); if (hang_flag== 1 && lie_flag == 1) for i = 1 : Integer_hang for j = 1 : Integer_lie Divided_image(i,j) = {Img((i-1)*N+1 : i*N , (j-1)*N+1 : j * N)}; end end elseif (hang_flag== 1 && lie_flag == 0) Img_insect_hang = zeros(Img_hang,Supplement_lie); Img_New_hang = [Img Img_insect_hang]; for i = 1 : Integer_hang for j = 1 : Integer_lie+1 Divided_image(i,j) = {Img_New_hang((i-1)*N+1 : i*N , (j-1)*N+1 : j * N)}; end end elseif (hang_flag== 0 && lie_flag == 1) Img_insect_lie = zeros(Supplement_hang,Img_lie); Img_New_lie = [Img ; Img_insect_lie]; for i = 1 : Integer_hang + 1 for j = 1 : Integer_lie Divided_image(i,j) = {Img_New_lie((i-1)*N+1 : i*N , (j-1)*N+1 : j * N)}; end end elseif (hang_flag== 0 && lie_flag == 0) Img_insect_hang = zeros(Img_hang,Supplement_lie); Img_New_hang = [Img Img_insect_hang]; [~,New_lie] = size(Img_New_hang); Img_insect_lie = zeros(Supplement_hang,New_lie); Img_New = [Img_New_hang ; Img_insect_lie]; for i = 1 : Integer_hang + 1 for j = 1 : Integer_lie+1 Divided_image(i,j) = {Img_New((i-1)*N+1 : i*N , (j-1)*N+1 : j * N)}; end end end end

  调用的话,如果需要将原图像分为5*5像素,即:Divided_image = Divide_into_N_block(5)


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
理解 Delphi 的类(十) - 深入方法[21] - 开放数组参数发布时间:2022-07-18
下一篇:
Delphi10.3的SpeedButton/BitBtn学习发布时间:2022-07-18
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap