I have a table of binary images and want to export them as a binary movie, but I can only export RGB movie instead of a binary one and the size of the movie is really large. Is there any way to export a binary movie?

Thanks, Liu

Movie = Table[MorphologicalTransform[Binarize[Import["E:\\McMaster\\Convert
Movie\\dead non-magnetic no field 3.avi", {"Frames", {i}}], Method -> "Entropy"], 
"Clean"], {i, 1, 10}]


Export["E:\\McMaster\\Convert Movie\\dead non-magnetic no field 3 B&W2.avi",
Movie[[1 ;; 10]], "FrameRate" -> 113];

  • $\begingroup$ Apparently, even if you explicitly feed a list of binary images to Export[], the colorspace of the resulting file is still RGB. Oh well. $\endgroup$ Oct 3 '18 at 14:11
  • $\begingroup$ Yes, they don't have the option of B&W in the color space. $\endgroup$
    – Liu Yu
    Oct 4 '18 at 1:24

The exported colors space for the PNG gets adapted if one choses maximal compression (PNG is lossless, btw.)

n = 200;
a = Image[CrossMatrix[{n, n}], "Binary"];
images = Table[ImageRotate[a, 6 2. Pi/360 i], {i, 1, 360}];
Export["a.png", images, "CompressionLevel" -> 1];

Import["a.png", "Summary"]

enter image description here

  • $\begingroup$ I guess this can work for an image but not for a movie since the color space supported by Mathematica doesn't include Black&White. $\endgroup$
    – Liu Yu
    Oct 4 '18 at 1:22
  • 1
    $\begingroup$ That's a multi-page PNG. Browser will play that as animation in the same way as animated GIF. Indeed, Mathematica's video capacities are very limited. But you can turn that PNG into any video format with the freely available, very powerful command line tool ffmpeg. $\endgroup$ Oct 4 '18 at 6:06
  • $\begingroup$ Yeah, sure! Thanks for helping! $\endgroup$
    – Liu Yu
    Oct 4 '18 at 15:49
  • $\begingroup$ You're welcome! $\endgroup$ Oct 4 '18 at 17:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.