Arrays 在Julia中的数组中创建填充矩形

Arrays 在Julia中的数组中创建填充矩形,arrays,julia,overlap,rectangles,Arrays,Julia,Overlap,Rectangles,我是Julia的新手,我正在努力理解基本的数据可视化。我正在使用以下内容创建二维噪波阵列: xRange, yRange = 1:1:300, 1:1:300 maxVal = 0.3 noiseArr = rand(length(xRange),length(yRange))*maxVal 结果数组如下所示(左)。我想识别特定的像素——由一个具有长度、宽度和旋转的矩形定义——并将这些值设置为一个已知的数字。最后,我想要下面(右)所示的图片 我没有软件包偏好,但我一直在看图片、OpenCV等。

我是Julia的新手,我正在努力理解基本的数据可视化。我正在使用以下内容创建二维噪波阵列:

xRange, yRange = 1:1:300, 1:1:300
maxVal = 0.3
noiseArr = rand(length(xRange),length(yRange))*maxVal
结果数组如下所示(左)。我想识别特定的像素——由一个具有长度、宽度和旋转的矩形定义——并将这些值设置为一个已知的数字。最后,我想要下面(右)所示的图片

我没有软件包偏好,但我一直在看图片、OpenCV等。我希望有一种直接的方法来做到这一点

我想识别特定的像素——由一个具有长度、宽度和旋转的矩形定义

知道长度、宽度和旋转角度不足以在平面上唯一地定位矩形。你还需要翻译

下面是一个简单的代码,它为您提供了一个可以执行的示例(它不是非常高效,但对于演示目的来说足够快):

函数矩形!(x1、x2、x3、noiseArr、val)
A=[x2-x1 x3-x1]
b=x1
iA=库存(A)
对于轴中的i(noiseArr,1),轴中的j(noiseArr,2)
it,jt=iA*([i,j]-b)

0这里是一个使用原语和
Luxor.jl

using Luxor

function b()
    Drawing(300, 300, "hello-world.png")
    background("black")
    sethue("white")
    #Luxor.scale(1,1)
    Luxor.translate(150, 30)
    Luxor.rotate(10 * pi / 180)
    w = 40
    h = 200
    rect(O, w, h, :fill)
    finish()
    preview()
end

现在,您可以提取变换矩阵并在其他地方使用它,而不是直接使用Luxor绘制它

using Plots
using GR
using LinearAlgebra

gr(size = (300, 300), legend = false)

function a(transform=Matrix{Int}(I, 3, 3))
    side = 300
    width = side
    height = side
    xs = [string("x", i) for i = 1:width]
    ys = [string("y", i) for i = 1:height]
    z = float((1:height) * reshape(1:width, 1, :))
    # Plots.heatmap(xs, ys, z, aspect_ratio = 1)

    white = maximum(z)

    # Draw a rectangle with a rotation matrix applied
    for x in 0:40
        for y in 0:200
            t = transform*[x;y;1]
            z[round(Int, t[2]), round(Int, t[1])] = white
        end
    end

    Plots.heatmap(xs, ys, z, aspect_ratio = 1)
end

using Luxor

function b()
    Drawing(300, 300, "hello-world.png")
    background("black")
    sethue("white")
    #Luxor.scale(1,1)
    Luxor.translate(100, 60)
    Luxor.rotate(-10 * pi / 180)
    w = 40
    h = 200
    rect(O, w, h, :fill)
    finish()
    preview()

    tranformation_matrix = Luxor.cairotojuliamatrix(Luxor.getmatrix())

    a(tranformation_matrix)
end
请注意,这会留下散乱的像素,因为我的for循环在栅格化填充时效率不高。从Luxor访问像素数据可能更好,或者使用对矩阵应用仿射变换的其他函数

注意julia中的绘图:


第一次绘图的时间很慢。要对它进行任何真正的迭代,您应该利用
Revise.jl
将测试函数保存在一个文件中,并将其包含在
includet(“test.jl”)
中。然后,您的julia会话是持久的,您只需等待您的
使用
语句一次。

您可以自己编写一个脚本(它们并不难)并填充内部。也许这将帮助您@phipsgabler,谢谢您的建议!在我最初的搜索中,我简单地考虑了一下这个问题,然后认为Julia肯定有一个更快的、开箱即用的功能,可以让人们轻松地排字。你知道有一个包可以在上面的noise数组中画一条线吗?啊,新的highlight.js东西不支持Julia。该代码被检测为YAML!这正是我所期待的,并且整合到一个简单的功能中。非常感谢。我很高兴能帮上忙。我希望后面的线性代数是清楚的-我们使用
Ax+b
函数将点
[0,0]
[0,1]
转换为
x1
x2
x3
using Plots
using GR
using LinearAlgebra

gr(size = (300, 300), legend = false)

function a(transform=Matrix{Int}(I, 3, 3))
    side = 300
    width = side
    height = side
    xs = [string("x", i) for i = 1:width]
    ys = [string("y", i) for i = 1:height]
    z = float((1:height) * reshape(1:width, 1, :))
    # Plots.heatmap(xs, ys, z, aspect_ratio = 1)

    white = maximum(z)

    # Draw a rectangle with a rotation matrix applied
    for x in 0:40
        for y in 0:200
            t = transform*[x;y;1]
            z[round(Int, t[2]), round(Int, t[1])] = white
        end
    end

    Plots.heatmap(xs, ys, z, aspect_ratio = 1)
end

using Luxor

function b()
    Drawing(300, 300, "hello-world.png")
    background("black")
    sethue("white")
    #Luxor.scale(1,1)
    Luxor.translate(100, 60)
    Luxor.rotate(-10 * pi / 180)
    w = 40
    h = 200
    rect(O, w, h, :fill)
    finish()
    preview()

    tranformation_matrix = Luxor.cairotojuliamatrix(Luxor.getmatrix())

    a(tranformation_matrix)
end