用MATLAB产生黑白投影条纹

用MATLAB产生黑白投影条纹,第1张

lines = 50 %黑白线对数

m = 5       %黑或白线宽度(像素),黑白宽度一致

n = 500     %图像高度

S = zeros(1,2*m)

S(1:m) = ones(1,m)

A = repmat(S,n,lines)

imshow(A)

im = zeros(300,300,3)

for i = 1:3

im(:,find(mod(0:299,30)+1 <= 10)+(i-1)*10,i) = 255

end

imshow(im)

imshow所需数据是个3维矩阵,前两维是图片的行和列,后一维三个度分别是红绿蓝的颜色数据,范围是[0 255] 如果你想把点x,y变成红色,就把矩阵的(x,y,1)设成255,(x,y,2)和(x,y,3)设成0就行了,依次类推绿是0,255,0 蓝是0,0,255注意矩阵的一个点是屏幕上一像素(很小),如果想看的清,最好把一个范围都弄上颜色

是这个意思吗?

以下这个函数可以模拟上面的图形,N是线条数,用鼠标拖动旋转,希望对你有帮助

function Moire_pattern_sim

global dt

N = 25%number of lines

h_f = figure

h_a = axes('parent',h_f)

set(h_f,...

  'windowbuttonupfcn',@stopdragfcn,...

  'windowbuttonmotionfcn','')

set(h_a,'buttondownfcn',@startdragfcn)

set(h_a,'dataaspectratio',[1 1 1],...

  'xlim',[-2,2],'ylim',[-2,2])

%mouse_down = false

xy_pre = [NaN,NaN]

rt_pt = [0 0]

rt_mat = repmat(rt_pt',1,2*N)

t = 0

x0 = repmat(linspace(-1,1,N),2,1)

y0 = repmat([-11],1,N)

x1 = x0

y1 = y0

l1 = zeros(1,N)

for k = 1:N

  line(x0(:,k),y0(:,k),'color',[0 0 0],'linestyle','-',...

      'linewidth',2)

  l1(k) = line(x1(:,k),y1(:,k),'color',[0 0 1],'linestyle','-',...

      'linewidth',2)

end

  function startdragfcn(varargin)

      %mouse_down = true

      set(h_f,'windowbuttonmotionfcn',@draggingfcn)

      pt = get(h_a,'currentpoint')

      xy_pre = pt(1,1:2)

  end

  function stopdragfcn(varargin)

      %mouse_down = false

      set(h_f,'windowbuttonmotionfcn','')

  end

  function draggingfcn(varargin)

      %if mouse_down

      pt = get(h_a,'currentpoint')

      v1 = xy_pre-rt_pt

      v2 = pt(1,1:2)-rt_pt

      xy_pre = pt(1,1:2)

      dt = atan2(v2(2),v2(1))-atan2(v1(2),v1(1))

      t = t+dt

      t = t/2

      A = [cos(t),-sin(t)sin(t),cos(t)]

      xy1 = A*([[x1(1,:),x1(2,:)][y1(1,:),y1(2,:)]]-rt_mat)+rt_mat

      x1 = [xy1(1,1:N)xy1(1,N+1:2*N)]

      y1 = [xy1(2,1:N)xy1(2,N+1:2*N)]

      for kk = 1:N

          set(l1(kk),...

              'xdata',x1(:,kk),...

              'ydata',y1(:,kk))

      end

      %end

  end

end


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/12129914.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-21
下一篇 2023-05-21

发表评论

登录后才能评论

评论列表(0条)

保存