Index in position 3 exceeds array bounds. Index must not exceed 1.

18 visualizzazioni (ultimi 30 giorni)
clc
clear all
close all
warning off
im1=imread('C:\Users\TULPAR\Desktop\res1.bmp');
im2=imread('C:\Users\TULPAR\Desktop\res2.bmp');
r1=im1(:,:,1);
g1=im1(:,:,2);
b1=im1(:,:,3);
r2=im2(:,:,1);
g2=im2(:,:,2);
b2=im2(:,:,3);
a=myown(r1,r2);
b=myown(g1,g2);
c=myown(b1,b2);
nexttile;
imshow(im1);
nexttile;
imshow(im2);
d=cat(3,a,b,c);
nexttile
imshow(d);
myown
function mattu=myown(p,q)
M = zeros(256,1,'uint8');
hist1 = imhist(p);
hist2 = imhist(q);
cdf1 = cumsum(hist1) / numel(p);
cdf2 = cumsum(hist2) / numel(q);
for idx = 1 : 256
[~,ind] = min(abs(cdf1(idx) - cdf2));
M(idx) = ind-1;
end
[H, W] = size(p);
mattu=zeros(H,W,'uint8');
for x = 1: H
for y = 1:W
mattu(x,y) =M(double(p(x,y))+1);
end
end
end
Index in position 3 exceeds array bounds. Index must not exceed 1. I get an error
  1 Commento
Jan
Jan il 19 Nov 2021
warning off
This is an extremely bad idea. Warnings are the best friend of programmers. Do not switch them off.
Please post the complete error message. Then we do not have to guess, here the error occurs.

Accedi per commentare.

Risposte (1)

Cris LaPierre
Cris LaPierre il 19 Nov 2021
You have a variable that is an mxnx1 array, and your code is telling MATLAB to index the 3rd dimension with a value >1.
theta1 = rand(3,2,1);
% Works
theta1(1,2,1)
ans = 0.7282
ans = 0.7707
ans = 0.7707
% Doesn't work
theta1(1,2,3)
Index in position 3 exceeds array bounds. Index must not exceed 1.

Tag

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by