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

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.

댓글을 달려면 로그인하십시오.

추가 답변 (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 Exchange에서 Mathematics and Optimization에 대해 자세히 알아보기

질문:

2018년 1월 13일

댓글:

2018년 1월 13일

Community Treasure Hunt

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

Start Hunting!

Translated by