Message Boards Message Boards

Save high resolution fractals directly to disk?

Posted 5 years ago

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.

POSTED BY: Rick Jarosh
3 Replies
Posted 5 years 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.

POSTED BY: Rick Jarosh
Posted 5 years 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 BY: Brad Chalfan
Posted 5 years ago

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

POSTED BY: Rick Jarosh
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