[英]Calling function from Julia file does not read image in Python file
In Julia I have built a function that changes an image a little bit.在 Julia 中,我构建了一个稍微改变图像的函数。 The function takes in as input following type
该函数采用以下类型作为输入
Matrix{RGB{N0f8}} (alias for Array{RGB{Normed{UInt8, 8}}, 2})
I have created environment where I use Julia and Python.我创建了使用 Julia 和 Python 的环境。 So in Python I want to test function on the cifar database.
所以在 Python 中,我想在 cifar 数据库上测试函数。 I want to change the images in the cifar database with my function.
我想用我的函数更改 cifar 数据库中的图像。 But whenever I try to run the function from Julia on images in the Python file, I get this error:
但是,每当我尝试从 Julia 对 Python 文件中的图像运行该函数时,都会收到此错误:
JULIA: BoundsError: attempt to access 100×100×3 Array{Float32, 3} at index [1, 1]
Even through if I try to access this coordinates directly like this in Python:即使我尝试在 Python 中像这样直接访问这个坐标:
image[1, 1]
it is completely fine and gives me the rgb values.它完全没问题,并给了我 rgb 值。 So I was curious maybe there is some function from images that I could apply?
所以我很好奇也许我可以应用图像中的一些功能?
100×100×3 Array{Float32, 3} at index [1, 1]
100×100×3 数组{Float32, 3} 在索引 [1, 1]
you need 3 numbers to index a single element of this 3D array.您需要 3 个数字来索引此 3D 数组的单个元素。 If I have to guess, I would think the
R
pixel of the image[1, 1]
in Python would be image[1, 1, 1]
in Julia, and the G
pixel is image[1, 1, 2]
, and the B
pixel is image[1, 1, 3]
如果我不得不猜测,我会认为 Python 中
image[1, 1]
的R
像素是 Julia 中的image[1, 1, 1]
,而G
像素是image[1, 1, 2]
,并且B
像素是image[1, 1, 3]
looking at this example: https://juliaimages.org/latest/tutorials/arrays_colors/#fixedpoint看这个例子: https ://juliaimages.org/latest/tutorials/arrays_colors/#fixedpoint
I think given a 3D array, you can convert it to an RGB matrix by using this from Images.jl
:我认为给定一个 3D 数组,您可以使用
Images.jl
中的这个将其转换为 RGB 矩阵:
using Images
img = colorview(RGB, reshape(image, (3, 100, 100)))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.