Ask Your Question
0

How to import images in sagemath?

asked 2 years ago

ajit gravatar image

Is there convenient way of importing images in various format such is PNG, JPG etc in Sagemath other than using python packages?

Preview: (hide)

Comments

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?

John Palmieri gravatar imageJohn Palmieri ( 2 years ago )

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,

Emmanuel Charpentier gravatar imageEmmanuel Charpentier ( 2 years ago )

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.

ajit gravatar imageajit ( 2 years ago )

1 Answer

Sort by » oldest newest most voted
0

answered 2 years ago

ortollj gravatar image

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)
Preview: (hide)
link

Comments

Thanks a lot jean-pierre Ortolland. It is helpful.

ajit gravatar imageajit ( 2 years ago )

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2 years ago

Seen: 710 times

Last updated: Feb 03 '23