2

I am trying to manipulate and save an image to file and it doesn't seem to be working from a function. It does, however, work in the command window. I have tried save, saveas, fprint, and others with no luck.

A = imread('contourSS.jpg'); B = rgb2gray(A);
imwrite(B, 'new_image.gif', 'gif');

Nothing shows up in the MATLAB directory when I run this code from a function, but it does show up in the MATLAB directory when I run it from the command window. Any ideas?
Thanks in advance.

4

1 に答える 1

2

ファイルを正しいディレクトリに保存していますか? 関数にadd を追加disp(pwd)してみてください。保存しているディレクトリも表示されます。

また、ファイルを保存するときは、完全なパスを使用することをお勧めします。コードを次のように変更することを検討してください。

imgDir = /home/user/image;
readfile = fullfile( imgDir, 'contourSS.jpg');
writefile = fullfile( imgDir, 'new_image.gif');

A = imread(readfild); B = rgb2gray(A);
imwrite(B, writefile, 'gif');
于 2012-10-26T20:16:08.893 に答える