i am getting the error while reading the images

ipDir = '../Dataset/photos'; isDir = '../Dataset/sketches';
files_p = dir([ipDir '*.jpg']); files_s = dir([isDir '*.jpg']);
tmp1=imread([ipDir files_p(1).name]); Index exceeds matrix dimensions.
Error in createTrainingData_color (line 13) tmp1=imread([ipDir files_p(1).name]);
I am getting the above error. Please help me.
I am getting the error while reading the images.

 Akzeptierte Antwort

Image Analyst
Image Analyst am 13 Jan. 2018

0 Stimmen

Evidently the length is zero and so when you try to access index 1, it says "Index exceeds matrix dimensions." Try this more robust way:
if length(files_p) > 0
fullFileName = fullfile(ipDir, files_p(1).name);
tmp1=imread(fullFileName);
end

2 Kommentare

files_p = dir([ipDir '*.jpg']); files_s = dir([isDir '*.jpg']);
%Find the nubmer files and the size of images
tmp1=imread([ipDir , files_p(1).name]); nFile = numel(files_p); [nRow, nCol, nCh] = size(tmp1);
%initialize matrix for data pImg_luv = zeros(nRow,nCol,nCh, nFile); pImg_rgb = zeros(nRow,nCol,nCh, nFile);
pImg = zeros(nRow,nCol,nFile); sImg = zeros(nRow,nCol,nFile); intImg = zeros(nRow,nCol,nFile); nRowPatch = nRow-pSize(1); nColPatch = nCol- pSize(2); squareSum = zeros(nRowPatch, nColPatch, nFile);
for i=1:nFile tmp1=imread([ipDir files_p(i).name]); pImg(:,:,i)=single(rgb2gray(tmp1));
pImg_rgb(:,:,:,i)= tmp1;
pImg_luv(:,:,:,i)= rgb2luv(tmp1);
intImg(:,:,i) = integralimage(pImg(:,:,i).^2);
%IRs
for m=1:nRowPatch
for n=1:nColPatch
squareSum(m,n,i)=intImg(m,n,i)+intImg(m+pSize(1)-1,n+pSize(2)-1,i)-intImg(m,n+pSize(2)-1,i)-intImg(m+pSize(1)-1,n,i);
end
end
tmp2=imread([isDir files_s(i).name]);
sImg(:,:,i)=single(tmp2);
end
this is the code if i mention yours code i got another error pl check he code if possible
Now you've totally confused us. You've accepted the answer but then you've posted chunks of code in three different locations and say it's not solved. Please clarify. Edit or delete your other posts so you just have one response to me in one place.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (2)

Pavan Kumar M.P
Pavan Kumar M.P am 13 Jan. 2018

0 Stimmen

function [pImg, pImg_rgb, sImg] = ... createTrainingData_color(ipDir, isDir, opFile, pSize)
addpath('utils/');
%ipDir='../Dataset/photos/'; %isDir='../Dataset/photos/';
files_p = dir([ipDir '*.jpg']); files_s = dir([isDir '*.jpg']);
%Find the nubmer files and the size of images
tmp1=imread([ipDir , files_p(1).name]); nFile = numel(files_p); [nRow, nCol, nCh] = size(tmp1);
%initialize matrix for data pImg_luv = zeros(nRow,nCol,nCh, nFile); pImg_rgb = zeros(nRow,nCol,nCh, nFile);
pImg = zeros(nRow,nCol,nFile); sImg = zeros(nRow,nCol,nFile); intImg = zeros(nRow,nCol,nFile); nRowPatch = nRow-pSize(1); nColPatch = nCol- pSize(2); squareSum = zeros(nRowPatch, nColPatch, nFile);
for i=1:nFile tmp1=imread([ipDir files_p(i).name]); pImg(:,:,i)=single(rgb2gray(tmp1));
pImg_rgb(:,:,:,i)= tmp1;
pImg_luv(:,:,:,i)= rgb2luv(tmp1);
intImg(:,:,i) = integralimage(pImg(:,:,i).^2);
%IRs
for m=1:nRowPatch
for n=1:nColPatch
squareSum(m,n,i)=intImg(m,n,i)+intImg(m+pSize(1)-1,n+pSize(2)-1,i)-intImg(m,n+pSize(2)-1,i)-intImg(m+pSize(1)-1,n,i);
end
end
tmp2=imread([isDir files_s(i).name]);
sImg(:,:,i)=single(tmp2);
end
save(opFile, 'pImg', 'pImg_rgb', 'pImg_luv', 'squareSum', 'sImg', 'files_p', 'files_s');
Pavan Kumar M.P
Pavan Kumar M.P am 13 Jan. 2018

0 Stimmen

function [pImg, pImg_rgb, sImg] = ... createTrainingData_color(ipDir, isDir, opFile, pSize)
addpath('utils/');
%ipDir='../Dataset/photos/'; %isDir='../Dataset/photos/';
files_p = dir([ipDir '*.jpg']); files_s = dir([isDir '*.jpg']);
%Find the nubmer files and the size of images
tmp1=imread([ipDir , files_p(1).name]); nFile = numel(files_p); [nRow, nCol, nCh] = size(tmp1);
%initialize matrix for data pImg_luv = zeros(nRow,nCol,nCh, nFile); pImg_rgb = zeros(nRow,nCol,nCh, nFile);
pImg = zeros(nRow,nCol,nFile); sImg = zeros(nRow,nCol,nFile); intImg = zeros(nRow,nCol,nFile); nRowPatch = nRow-pSize(1); nColPatch = nCol- pSize(2); squareSum = zeros(nRowPatch, nColPatch, nFile);
for i=1:nFile tmp1=imread([ipDir files_p(i).name]); pImg(:,:,i)=single(rgb2gray(tmp1));
pImg_rgb(:,:,:,i)= tmp1;
pImg_luv(:,:,:,i)= rgb2luv(tmp1);
intImg(:,:,i) = integralimage(pImg(:,:,i).^2);
%IRs
for m=1:nRowPatch
for n=1:nColPatch
squareSum(m,n,i)=intImg(m,n,i)+intImg(m+pSize(1)-1,n+pSize(2)-1,i)-intImg(m,n+pSize(2)-1,i)-intImg(m+pSize(1)-1,n,i);
end
end
tmp2=imread([isDir files_s(i).name]);
sImg(:,:,i)=single(tmp2);
end
save(opFile, 'pImg', 'pImg_rgb', 'pImg_luv', 'squareSum', 'sImg', 'files_p', 'files_s');
this is the actual code i got the problem while reading the imaage by using imread(); pl help me

Kategorien

Mehr zu Mathematics and Optimization finden Sie in Hilfe-Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by