user3820043
user3820043

Reputation: 11

I am encountering an error while using imwrite

I am new to image processing and what I am trying to do is resize an image and store it in tif format, but command window reports an error saying "you don't have the permission to write"

my code is imwrite(B,'myNewFile.tif'); and after running it shows

Error using imwrite (line 10)
Unable to open file "myNewFile.tif" for writing. You may not have write permission.

Do I have to create a file by the name 'myNewFile' before writing the above code?

Upvotes: 1

Views: 3373

Answers (1)

Shai
Shai

Reputation: 114796

As the error message states, you are trying to write the file myNewFile.tif to the current working directory. However, you do not have writing permission in the current working direcoty. This is an OS issue, not a Matlab one.

What you can do is change the current working directory (using cd command) and write the image to a different folder where you do have writing permissions.

Alternatively, you can supply a full path to the image file name, directing it to a folder where you have writing permissions.

imwrite( B, fullfile( '/path/to/where/you/can/write', 'myNewFile.tif' ) );

Here are links to the description of some Matlab commands that might help you:

  • pwd can be used to check what is your current working directory.
  • You can use cd to change the current working directory.
  • fullfile helps you construct file names and paths in a generic way without worrying about OS pecularities.

Upvotes: 3

Related Questions