2 views (last 30 days)
Show older comments
Pavan Kumar M.P on 13 Jan 2018
Commented: Image Analyst on 13 Jan 2018
Accepted Answer: Image Analyst
Open in MATLAB Online
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.
0 Comments Show -2 older commentsHide -2 older comments
Show -2 older commentsHide -2 older comments
Sign in to comment.
Sign in to answer this question.
Accepted Answer
Image Analyst on 13 Jan 2018
⋮
Open in MATLAB Online
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 Comments Show NoneHide None
Show NoneHide None
Pavan Kumar M.P on 13 Jan 2018
Direct link to this comment
https://support.mathworks.com/matlabcentral/answers/376990-i-am-getting-the-error-while-reading-the-images#comment_524365
Open in MATLAB Online
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 on 13 Jan 2018
Direct link to this comment
https://support.mathworks.com/matlabcentral/answers/376990-i-am-getting-the-error-while-reading-the-images#comment_524378
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.
Sign in to comment.
More Answers (2)
Pavan Kumar M.P on 13 Jan 2018
Open in MATLAB Online
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');
0 Comments Show -2 older commentsHide -2 older comments
Show -2 older commentsHide -2 older comments
Sign in to comment.
Pavan Kumar M.P on 13 Jan 2018
Open in MATLAB Online
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
0 Comments Show -2 older commentsHide -2 older comments
Show -2 older commentsHide -2 older comments
Sign in to comment.
Sign in to answer this question.
See Also
Categories
SciencesAgriculture
Find more on Agriculture in Help Center and File Exchange
Tags
- err
- image processing
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- Deutsch
- English
- Français
- United Kingdom(English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)
Contact your local office