tricknology
tricknology

Reputation: 1138

Simple imwrite does not write to file

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.

Upvotes: 2

Views: 1413

Answers (1)

slayton
slayton

Reputation: 20319

Are you sure the you're saving the file to the correct directory? Try adding adding disp(pwd) to the function, it will display the directory that you are saving too.

Also its generally a good idea to use complete paths when saving a file. Consider changing your code to this:

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');

Upvotes: 2

Related Questions