How to solve "index exceeds matrix dimension" while using imread

I am trying to program the Wiener Filter. And the sizes of pictures that I am going to read range from 5MB to around 15MB. When I imread the picture, there is error saying "Index exceed the matrix dimension"
Error:
Index exceeds matrix dimensions.
Error in QM (line 3)
im=imread([base,files(1).name]);
Program:
base='Users\aa\Downloads\';
files = dir( fullfile(base,'1.tif') );
im=imread([base,files(1).name]);
I = im2double(im);
imshow(I);
title('Original Image (courtesy of MIT)');
LEN = 21;
THETA = 11;
PSF = fspecial('motion', LEN, THETA);
blurred = imfilter(I, PSF, 'conv', 'circular');
figure, imshow(blurred)
noise_mean = 0;
noise_var = 0.0001;
blurred_noisy = imnoise(blurred, 'gaussian', ...
noise_mean, noise_var);
figure, imshow(blurred_noisy)
title('Simulate Blur and Noise')
estimated_nsr = 0;
wnr2 = deconvwnr(blurred_noisy, PSF, estimated_nsr);
figure, imshow(wnr2)
title('Restoration of Blurred, Noisy Image Using NSR = 0')
estimated_nsr = noise_var / var(I(:));
wnr3 = deconvwnr(blurred_noisy, PSF, estimated_nsr);
figure, imshow(wnr3)
title('Restoration of Blurred, Noisy Image Using Estimated NSR');

 採用された回答

Guillaume
Guillaume 2017 年 9 月 5 日

0 投票

The error is not in imread, the error is on line 3 of your program as the message says. My suspsicion is that files is empty, therefore the 1 index in files(1) indeed exceeds the matrix dimension of files.
I'll note that the path you pass to the dir function is not absolute. It therefore looks for '1.tif' in the 'Users\aa\Downloads' of the current directory whatever that is. Perhaps you're missing a 'C:\' ahead of your path?

3 件のコメント

Rui Zu
Rui Zu 2017 年 9 月 5 日
Thank you for your response! I changed my path and deleted the complicate input and it turns out to work!
Pavan Kumar M.P
Pavan Kumar M.P 2018 年 1 月 13 日
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]);
iam gettoing the above error please help me
Pavan Kumar M.P
Pavan Kumar M.P 2018 年 1 月 13 日
i am getting the error while reading the images.

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeMatrix Indexing についてさらに検索

製品

質問済み:

2017 年 9 月 5 日

コメント済み:

2018 年 1 月 13 日

Community Treasure Hunt

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

Start Hunting!

Translated by