How to import images in sagemath?
Is there convenient way of importing images in various format such is PNG, JPG etc in Sagemath other than using python packages?
Is there convenient way of importing images in various format such is PNG, JPG etc in Sagemath other than using python packages?
Hi @ajit
Maybe this example could help you (assuming you want to display an image in a cell ?, but not sure it is what you want)
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
import numpy as np
from matplotlib.pyplot import figure
#imgPath="C:\\Users\\User\\Documents\\IPYNBpc\\LinearAlgebraMIT\\" # from Firefox in W11
imgPath='/mnt/c/Documents and Settings/user/Mes documents/IPYNBpc/LinearAlgebraMIT/' # Firefox UBUNTU
figS=120
figure(num=None, figsize=(figS, 3*figS), dpi=100, facecolor='w', edgecolor='k')
img = mpimg.imread(imgPath+"GthChap1Exercice11.png")
imgplot = plt.imshow(img)
Please start posting anonymously - your entry will be published after you log in or create a new account.
Asked: 2023-02-02 18:40:09 +0100
Seen: 601 times
Last updated: Feb 03 '23
Sage is built on Python, so Python packages are the most natural choice. What do you mean by "import," what do you want to do with the images, and why not use Python packages?
What do you mean by "import"ing images ?
If you want to add external images in a Jupyter notebook havin Sage cells, the easiest solution, as pointed out by @John Palmieri, is to use the Python tools interfacing with Jupyter ; a simple Google search on "Jupyter import images" will point you to a lot of ways to do this.
The same holds, mutatis mutandis, for importing images in a document using Sage parts, such as a SageTeX document (where the standard tools for inserting images work), or an Org document (ditto).
If you want to import images whose content is to be processed by Sage, the first part is to load them as Python objects. Again, a Google query on "Python image processing" will give you pointers to a variety of ways.
HTH,
Thanks John for your detailed answer. I was trying to image compression using SVD with SageMath and wanted the image as a matrix in the format that Sage is able to find its SVD. I did use python packages and succeeded.