Message Boards Message Boards

GROUPS:

Save high resolution fractals directly to disk?

Posted 1 month ago
214 Views
|
3 Replies
|
0 Total Likes
|

I'm using a module that generates factals. It outputs the images to the relevant working notebook. To save images I have been using "Save Selection As" and the saving them to disc manually. With high resolution images the process can often take several minutes or cause crashes. Is there a way to write the image direclty to disk without having to output the image into the notebook window? I tried using Export but wasn't able to do it successfuly. Any advice would be appreciated.

3 Replies
Posted 1 month ago

PS I'm running Mathematica 11.1.1.0 on MacOS High Sierra 10.13.6

Posted 1 month ago

I often do something like this to save an image file into the same folder as the current notebook file:

(* pretend to generate a fractal *)
RandomImage[1, {1920, 1080}, ColorSpace -> "RGB"]

(* export the previous output into this notebook's directory as a png file *)
Export[FileNameJoin[{NotebookDirectory[], "output image.png"}], %]

Note that I used the NotebookDirectory function, which will fail if the current notebook hasn't actually been saved to disk yet. A simpler alternative is just something like Export["/my/path/output image.png", %]

Displaying large images in notebooks tends to use a lot of memory and can be slow in my experience, so if you can avoid displaying the image in a cell in the notebook, then less memory will be used. Maybe that's the cause of the crashes that you've seen?

Module[{img},
  (* pretend to generate a fractal, and store it in a variable *)
  img = RandomImage[1, {1920, 1080}, ColorSpace -> "RGB"];
  (* export it into this notebook's directory as a png file *)
  Export[FileNameJoin[{NotebookDirectory[], "output image.png"}], img]
]

(I tested the code above, and it works for me on MacOS 10.13.6, Mathematica 11)

Posted 1 month ago

That completely solves the problem. Displaying and saving the images in and from the notebooks was the cause of the issues. Thanks, you made my day.

Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract