Error using cd Argument must contain a string

I am getting this error while executing this code :
w = cd;
cd(DIAGPATH);
imwrite(image,[eyeimage_filename,'-normal.jpg'],'jpg');
cd(w);
% end diagnostics
%replace NaNs before performing feature encoding
coords = find(isnan(polar_array));
polar_array2 = polar_array;
polar_array2(coords) = 0.5;
avg = sum(sum(polar_array2)) / (size(polar_array,1)*size(polar_array,2));
polar_array(coords) = avg;
can anybody please explain it to me..need help. thankyou in advance.

 Risposta accettata

Stephen23
Stephen23 il 22 Feb 2016
Modificato: Stephen23 il 22 Feb 2016
Don't use cd for trivial code like this: simply construct the filepath using fullfile
im_path = fullfile(DIAGPATH, [eyeimage_filename,'-normal.jpg'] );
imwrite(image,im_path,'jpg');
Then you do not need any cd calls at all: this is a much faster and more robust way to write code. You will also find that the variable DIAGPATH is not a string, which it needs to be.

7 Commenti

hey thank you for ur positive reply. after making modification to my code :
% write out rings overlaying original iris image
im_path = fullfile('D:\matlab',[eyeimage_filename,'-normal.jpg'] );
imwrite(image,im_path,'jpg');
% end diagnostics
%replace NaNs before performing feature encoding
coords = find(isnan(polar_array));
polar_array2 = polar_array;
polar_array2(coords) = 0.5;
avg = sum(sum(polar_array2)) / (size(polar_array,1)*size(polar_array,2));
polar_array(coords) = avg;
following errors are occurring now can u please help me in this -
Error using horzcat
Dimensions of matrices being concatenated are not consistent.
Error in normaliseiris (line 167)
im_path = fullfile('D:\matlab',[eyeimage_filename,'-normal.jpg'] );
You need to check the variable eyeimage_filename: is it a string? What size is it? Tell me exactly the output of these commands:
class(eyeimage_filename)
size(eyeimage_filename)
ans =
double
ans =
150 200
these are the outputs.
@nisha: Do you see, that the variable "eyeimage_filename" does not contain a file name?
@jan can't i just pass the variable which may containing eyeimage_filename instead of passing 'Img_89_1_1.jpg'.
my code :
clear all;
close all;
clc;
I=imread('Img_89_1_1.jpg');
figure();imshow(I);
title('INPUT IMAGE');
grey_img=rgb2gray(I);
figure();imshow(grey_img);
title('Gray image');
edge_image=edge(grey_img,'canny');
figure();imshow(edge_image);
title('CANNY IMAGE');
figure; imshow(edge_image);
[ci,cp,out]=thresh(grey_img,38,50);
figure();imshow(out);
class(I)
size(I)
[polar_array, polar_noise] = normaliseiris(out, 84, 101,47,...
81, 106, 12,I, 302, 24);
for eyeimage_filename = I it prompt following error :
ans =
uint8
ans =
150 200 3
Error using horzcat
Dimensions of matrices being concatenated are not consistent.
Error in normaliseiris (line 167)
im_path = fullfile('D:\matlab',[eyeimage_filename,'-normal.jpg'] );
but when i put eyeimage_filename= 'Img_89_1_1.jpg', an image is created in my matlab folder like this.
please help !!
"can't i just pass the variable which may containing eyeimage_filename instead of passing 'Img_89_1_1.jpg'."
No, you can't.
An image is not a filename, an image is a numeric array of data, usually of class double or uint8.
A filename is a string, such as your string 'Img_89_1_1.jpg'.
You cannot use an array of numeric data for a filename. This makes no sense. Read the documentation for imwrite, or fullfile, or any other function that uses filenames: they all use strings. There is no mention of numeric arrays. Numeric arrays do not contain meta-data such as their origin filename, the date of creation or modification, your cousin's telephone number, or any other meta-data. Surprisingly, a numeric array contains numeric data!
To write an image to file you need two pieces of information: the image data (a numeric array) and the filename (a string). What do you possibly hope to achieve by giving imwrite two images arrays and no filename? Try this:
imwrite(I,im_path,'jpg');
That is all there is to it.
Nisha. Can you help me out with iris recognition code. I'm getting same error as you got in findcircle.m functions.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Convert Image Type in Centro assistenza e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by