How to fix error: "Index in position 1 is invalid. Array indices must be positive integers or logical values" caused by bad kernel
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hello everyone! I am making an automatic software in MATLAB (R2019b) which converts 2D images (e.g. depth maps, reflective maps etc.) into a 3D point cloud matrix. I have been investigating methods of denoising which finds the neighbours of a single point in a rxr kernel and stores their indices. This process is repeated for all points. I can't seem to find a reliable method of scanning the points on the edges as it will return an error that reads "Index in position 1 is invalid. Array indices must be positive integers or logical values." I thought padding the image in zeros would help but that seems to be only a temporary solution because once I increase the radius of the kernel, the same error pops up. If anyone can help solve this I would really appreciate it! I'll attach the code below:
clc; clear all; close all;
% Image and radius are going to be function variables but for testing purposes are set to constants
Image = [21:2:37; 90:98; 31:2:47; 71:79; 53:2:69; 41:49; 21:29; 81:89; 11:19] %input matrix
Radius = 3; % function variable
r = Radius - 2; % box filter parameter
%Indices of neighbouring points in a moving kernel for point cloud
Image = padarray(Image,[r,r],0,'both')
n = 1; % enables for indice loop
[row,col] = size(Image);
for i = 2: row - 1
for j = 2: col -1
LocationMat=zeros(row,col)
LocationMat(i-r:i+r,j-r:j+r)= 1 %Kernel rxr
Indices(n,:)=find(LocationMat); %finds the indices of the box kernel
n = n + 1;
end
end
I need some suggestions on a better method of implementing a rxr kernel since the kernel doesn't work anything but for 3x3. The problem is I cant the edges of the image so i cant get the neighbours of the edges.
Image =
21 23 25 27 29 31 33 35 37
90 91 92 93 94 95 96 97 98
31 33 35 37 39 41 43 45 47
71 72 73 74 75 76 77 78 79
53 55 57 59 61 63 65 67 69
41 42 43 44 45 46 47 48 49
21 22 23 24 25 26 27 28 29
81 82 83 84 85 86 87 88 89
11 12 13 14 15 16 17 18 19
LocationMat =
@ 1 0 0 0 0 0 0 0 0 0
1 1 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
I want to have a method of getting the neighbours for the @ point, by maybe a method of replicating the matrix when the edge is detected/
0 comentarios
Respuestas (1)
Star Strider
el 7 de Mzo. de 2021
I am not certain what you are doing.
Another option would be to set ‘hard’ limits on the indices, for example:
LocationMat(max(1,i-r):min(i+r,size(Image,1)), max(1,j-r):min(j+r,size(Image,2)))) = 1 %Kernel rx
I cannot test this because I am not certain what you are doing, so I defer to you to experiment with it.
0 comentarios
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!