Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Image 如何创建不同角度和厚度的对角线条纹图案?_Image_Matlab_Textures - Fatal编程技术网

Image 如何创建不同角度和厚度的对角线条纹图案?

Image 如何创建不同角度和厚度的对角线条纹图案?,image,matlab,textures,Image,Matlab,Textures,我想使用以下参数创建黑白对角条纹图案: h:图像的高度 w:图像的宽度 a:条带与X轴之间的角度 d:条纹之间的距离 t:条纹的厚度 这可以使用正弦光栅来完成,就像我发布的答案一样。但它有两个问题: 它不能保证条纹保持连接 它不能保证条纹的厚度保持相等 这是一个示例: diagStripes( [h h], pi/4, 20, 0.05); diagStripes( [h h], pi/6, 20, 0.03); 然后我实现了另一个函数,它的灵感来自。首先,它创建垂直/水平条纹图案,然后

我想使用以下参数创建黑白对角条纹图案:

  • h
    :图像的高度
  • w
    :图像的宽度
  • a
    :条带与X轴之间的角度
  • d
    :条纹之间的距离
  • t
    :条纹的厚度
这可以使用正弦光栅来完成,就像我发布的答案一样。但它有两个问题:

  • 它不能保证条纹保持连接
  • 它不能保证条纹的厚度保持相等
  • 这是一个示例:

    diagStripes( [h h], pi/4, 20, 0.05);
    diagStripes( [h h], pi/6, 20, 0.03);
    

    然后我实现了另一个函数,它的灵感来自。首先,它创建垂直/水平条纹图案,然后循环移动其行/列以创建对角线图案:

    function [ out ] = diagStripes( h, w, a, d, t )
    % wrap a between pi/4 and -3*pi/4
    a = -wrapTo2Pi(a);
    if a<-7*pi/4
        a=a+2*pi;
    elseif a<-3*pi/4
        a=a+pi;
    end
    
    if a>-(pi/4) % the acute angle between stripes and x axis is greater than pi/4
        dy = round(abs(d/cos(a))); % vertical distance between stripes
        ty = max(1, round(abs(t/cos(a)))); % vertical thickness of stripes
        n = ceil(h/dy); % maximum number of stripes
        out = repmat([false(ty, 1); true(dy-ty, 1)], n, w); % create horizontal stripes
        x = 1:w;
        y = round(tan(a)*x); % calculate shift amount of each column
        for ii=x
            out(:, ii) = circshift(out(:, ii), y(ii), 1);
        end
    else % the acute angle between stripes and x axis is less than pi/4
        dx = round(abs(d/sin(a))); % horizontal distance between stripes
        tx = max(1, round(abs(t/sin(a)))); % horizontal thickness of stripes
        n = ceil(w/dx); % maximum number of stripes
        out = repmat([false(1, tx), true(1, dx-tx)], h, n); % create vertical stripes
        y = 1:h;
        x = round(cot(a)*y); % calculate shift amount of each row
        for ii=y
            out(ii, :) = circshift(out(ii, :), x(ii), 2);
        end
    end
    out = out(1:h, 1:w); % crop the result, out may have more rows or columns than desired values (n*(dx or dy))
    end
    
    function[out]=diagstrips(h、w、a、d、t)
    %在pi/4和-3*pi/4之间换行
    a=-wrapTo2Pi(a);
    
    如果a假设只需要与图形相关,我将坚持使用第一种方法并依赖于抗锯齿技术。例如:

    out = diagStripes(4 .* [h h], pi/6, 4*20, 0.03)
    out = imresize(out, 0.25);
    
    也许你必须保持灰度,并在重新缩放后进行二进制转换。根据您以前的方法:

    binary = out < (cos(pi*0.03)+1)/2;
    
    binary=out<(cos(pi*0.03)+1)/2;
    
    假设只需要与图形相关,我将坚持使用第一种方法,并依赖抗锯齿技术。例如:

    out = diagStripes(4 .* [h h], pi/6, 4*20, 0.03)
    out = imresize(out, 0.25);
    
    也许你必须保持灰度,并在重新缩放后进行二进制转换。根据您以前的方法:

    binary = out < (cos(pi*0.03)+1)/2;
    
    binary=out<(cos(pi*0.03)+1)/2;
    
    是否运行探查器(函数“profile”)并识别“慢行”?@G.J大约75%的运行时间花费在
    circshift
    行中。是否运行探查器(函数“profile”)并识别“慢行”?@G.J大约75%的运行时间花费在
    circshift
    行中。