简体   繁体   English

Octave认为,我要imread()的图像不存在

[英]Octave thinks, that image I want to imread() doesn't exist

I'm writing a function in Octave to easily add particles on an image, but I have a problem. 我在Octave中编写了一个函数,可以轻松在图像上添加粒子,但是我遇到了问题。

function [ out ] = enparticle( mainImg, particleNames, particleData, frames, fpp, sFrame, eFrame )

  %particleData format:
  % [ p1Xline p1StartHeight p1EndHeight;
  %   p2Xline p2StartHeight p2EndHeight;
  %   p3Xline p3StartHeight p3EndHeight;
  % ... ]
  %particleNames format:
  % [ p1Name;
  %   p2Name;
  %   p3Name;
  % ... ]

  pAmount = size(particleData, 1);

  for i= 1:pAmount
    tmp = particleNames(i,:) 
    [ pIMG pMAP pALPHA ] = imread( tmp );
  end

end

When I run this simple code with 当我使用以下简单代码运行时

enparticle( "ffield.png", [ "p_dot.png"; "p_star.png"; "p_dot.png" ], [ 100 50 100; 200 50 100; 300 50 100 ], 30, 10, 5, 25 )

I get this written in console 我把这个写在控制台上

tmp = p_dot.png
error: imread: unable to find file p_dot.png
error: called from
    imageIO at line 71 column 7
    imread at line 106 column 30
    enparticle at line 24 column 23

When I try to imread() file this way, Octave thinks, that there is no file named like this. 当我尝试以这种方式imread()文件时,Octave认为没有这样的文件。 But it is actually. 但这是真的。 In the same folder as script file. 与脚本文件位于同一文件夹中。

The most curious thing is that, when I change 最奇怪的是,当我改变

    tmp = particleNames(i,:) 

to

    tmp = particleNames(:,:)

and Octave assigns all names to tmp as array, it magically find all the files with passed names. Octave将所有名称分配给tmp作为数组,它神奇地找到了所有带有传递名称的文件。

But it's not the way I want it to work, because all files will be replaced, or merged, or sth along image processing then. 但这不是我想要的方式,因为所有文件都将被替换,合并或随之进行图像处理。

Why I'm trying to do it that way is corelated with fact, that I want to put every frame (of image and alpha) separately into a cell array later. 为什么我要尝试这样做与事实有关,我想稍后将每个帧(图像和Alpha)分别放入单元格数组中。

I totally don't have any clue, about what I do wrong there and can't google it anywhere also :( 我完全不知道我在那里做错了什么,也无法在任何地方使用谷歌搜索:(

The code: 编码:

filenames = [ "p_dot.png"; "p_star.png"; "p_dot.png" ]

does not do what you think it does. 不按照您的想法去做。 This will create a 2 dimensional array of characters. 这将创建一个二维字符数组。 See 看到

octave> size (filenames)
ans =

    3   10

Of interest note is that it lists 10 columns. 有趣的是它列出了10列。 Take a look at your filenames and you will notice that their file names are of different lengths, two have length 9 and one has length 10. But this is just like a numeric matrix, the only difference is you have ascii characters. 查看您的文件名,您会发现它们的文件名长度不同,两个文件名的长度为9,一个文件名的长度为10。但这就像一个数字矩阵,唯一的区别是您拥有ascii字符。 And like a numeric matrix, all rows must have the length. 并且像数字矩阵一样,所有行都必须具有长度。 What is happening, is that the shortest rows get padded with whitespace. 发生的是,最短的行被空白填充。 You can confirm this by checking the ascii decimal code of your filenames: 您可以通过检查文件名的ascii十进制代码来确认这一点:

octave> int8 (filenames)
ans =

  112   95  100  111  116   46  112  110  103   32
  112   95  115  116   97  114   46  112  110  103
  112   95  100  111  116   46  112  110  103   32

Note how the first and third row end in '32'. 请注意第一行和第三行如何以'32'结尾。 In ASCII, that's the space character (see the wikipedia article about ASCII which has the tables) 在ASCII中,这是空格字符(请参阅有关表的ASCIIWikipedia文章

So the problem is not that imread does not find a file named 'p_dot.png', the problem is that it does not find a file named 'p_dot.png '. 因此,问题不在于imread找不到名为“ p_dot.png”的文件,而是在于它找不到名为“ p_dot.png”的文件。

You should not be using character arrays for this. 您不应该为此使用字符数组。 Instead, use a cell array. 而是使用单元格数组。 In a cell array of char arrays. 在char数组的单元格数组中。 Like so: 像这样:

filenames = {"p_dot.png", "p_start.png", "p_dot.png"}
for i = 1:numel (filenames)
  fname = filenames{i};
  [pIMG, pMAP, pALPHA] = imread (fname);
  ## do some stuff
endfor

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法在 Octave 5.2.0 中使用 imread() 读取 tiff 图像,出现此错误:Magick++ 异常 - Can't read tiff image using imread() in Octave 5.2.0 , getting this error : Magick++ exception 读八度到读cv2 - imread octave to imread cv2 读取功能在Matlab中不起作用 - imread function doesn't work in matlab 如何修复“图像”pyimage10“不存在”错误,为什么会发生? - How do I fix the “image ”pyimage10“ doesn't exist” error, and why does it happen? 如何将使用cv2.imread('img.png',cv2.IMREAD_UNCHANGED)读取的图像转换为cv2.imread('img.png',cv2.IMREAD_COLOR)的格式 - How do i convert an image read with cv2.imread('img.png',cv2.IMREAD_UNCHANGED) to the format of cv2.imread('img.png',cv2.IMREAD_COLOR) 我想使用OpenCV来检测静态图像中的2D条形码,但是文档似乎没有涵盖它 - I want to use OpenCV to detect 2D barcodes in a static image but the documentation doesn't seem to cover it 带有IMREAD_COLOR的图像中不使用OpenCV,DFT函数 - OpenCV, DFT function don't use in the image with IMREAD_COLOR 如何将用裁剪裁剪的图像读入变量? - How can I imread the image that I cropped with imcrop into a variable? 读入后更改图像 - imread changes the image after reading it in 从窗口读取图像 - read an image from windows with imread
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM