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.

 採用された回答

Image Analyst
Image Analyst 2018 年 1 月 13 日

0 投票

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 件のコメント

Pavan Kumar M.P
Pavan Kumar M.P 2018 年 1 月 13 日
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
Image Analyst
Image Analyst 2018 年 1 月 13 日
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.

サインインしてコメントする。

その他の回答 (2 件)

Pavan Kumar M.P
Pavan Kumar M.P 2018 年 1 月 13 日

0 投票

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 2018 年 1 月 13 日

0 投票

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

カテゴリ

ヘルプ センター および File ExchangeMathematics and Optimization についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by