ASKSAGE: Sage Q&A Forum - Latest question feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Tue, 16 Jun 2020 04:48:43 -0500Pil image colors not requestedhttps://ask.sagemath.org/question/52038/pil-image-colors-not-requested/ Hi
Ubuntu 18.04 SageMath 9.1 Jupyter notebook
does anyone know why the colors are not the ones i asked for? :
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
import numpy as np
from matplotlib.pyplot import figure
figS=2
figure(num=None, figsize=(figS, 1*figS), dpi=150, facecolor='w', edgecolor='k')
from PIL import Image, ImageColor
imSize=(10,10) # Image size= 10x10 pixels
imageModeL=["L", "LA", "P", "PA"]
iMmode=imageModeL[0]
im = Image.new(iMmode, imSize)
for i in range(imSize[0]) :
for j in range(imSize[1]) :
im.putpixel((i,j), ImageColor.getcolor("white",iMmode))
im.putpixel((0,0), ImageColor.getcolor('red',iMmode))
im.putpixel((1,0), ImageColor.getcolor('blue', iMmode))
im.putpixel((3,3), ImageColor.getcolor('pink', iMmode))
im.putpixel( (2, 2), ImageColor.getcolor('green', iMmode))
imgPath="/home/ortollj/Downloads/SageMath/IPYNB/"
im.save(imgPath+'tenXtenPixels.png')
img = mpimg.imread(imgPath+"tenXtenPixels.png")
imgplot = plt.imshow(img)
![image description](/upfiles/15923008595368105.png)
ortolljTue, 16 Jun 2020 04:48:43 -0500https://ask.sagemath.org/question/52038/How to fix problem when creating image histogramhttps://ask.sagemath.org/question/48833/how-to-fix-problem-when-creating-image-histogram/ Hello,
I'm trying to develop a function that calculates histograms for the colored images.
When I run my program it says 'too many values to unpack (expected 2)'. What am I doing wrong here?
Below is my code
Collor_Channel =("r" , "g", "b")
PixelNum, Collor_Channel = im.shape
ImageHistogram = np.zeros(256)
for i in range(PixelNum[0]):
for j in range(PixelNum[1]):
for x in range(PixelNum[2]):
totalvalue = im [j,i,x]
ImageHistogram[int(totalvalue)] += 1
return ImageHistogram
isidaThu, 21 Nov 2019 06:02:42 -0600https://ask.sagemath.org/question/48833/How to create your own function for image histogram?https://ask.sagemath.org/question/48832/how-to-create-your-own-function-for-image-histogram/ hello,
I'm trying to create my own function to calculate histograms for colored images. I wrote my function it returns a message " too many values to unpack (expected 2)"
Below is my code for the Histogram
(r,g,b)=cv2.split(im)
Collor_Channel =("r" , "g", "b")
PixelNum, Collor_Channel = im.shape
mageHistogram = np.zeros(256, im.shape)
for i in range(PixelNum[0]):
for j in range(PixelNum[1]):
for x in range(PixelNum[2]):
totalvalue = im(j,i,x)
ImHistogram[int(totalvalue*255)] += 1
return ImHistogram
enter code hereisidaThu, 21 Nov 2019 05:51:12 -0600https://ask.sagemath.org/question/48832/Image.PNG definition degraded, in notebook viewhttps://ask.sagemath.org/question/44682/imagepng-definition-degraded-in-notebook-view/Hi
is there a way to improve the definition in Jupyter notebook ?
from PIL import Image
img=Image.open("C:\\Users\\jean-pierre\\Documents\\SageMath\\IPYNB\\"+"Satellites.png")
matrix_plot(img, origin='upper',aspect_ratio=1)
![image description](/upfiles/15449698434825793.png)
what I see in notebook is very poor in notebook !
ortolljSun, 16 Dec 2018 08:26:19 -0600https://ask.sagemath.org/question/44682/Inverse image transformhttps://ask.sagemath.org/question/41646/inverse-image-transform/ Does Sage have an inverse image transform?
By that, I mean is there a function where, given an image $X$, and function $f$, it generates an image $Y$, such that pixel $p$ of $Y$ is assigned the color of $f(p) \in X$?
Note that for convenience, you can also say what rectangle the input and output image represent. (I.e. you could say that pixels in $Y$ correspond to points in $[-1,1] \times [-1,1]$.
For reference, here is mathematica's version is called `ImageTransformation`.MathMan42Mon, 19 Mar 2018 13:50:10 -0500https://ask.sagemath.org/question/41646/Dicom files with sagehttps://ask.sagemath.org/question/38090/dicom-files-with-sage/
Hi everybody! Please is there a way to manage DICOM files with sage? This is possible with pure python, using pydicom. How to use this tool under sage?
Thank you in advance.cddMon, 26 Jun 2017 10:10:38 -0500https://ask.sagemath.org/question/38090/right click dropdown on graph doesn't workhttps://ask.sagemath.org/question/37212/right-click-dropdown-on-graph-doesnt-work/I made a 3d graph and right clicked for viewing choices. I get a list but clicking on any of the list items does nothing. Using Sage on Windows 8 in Virtualbox.cybervigilanteThu, 06 Apr 2017 23:03:42 -0500https://ask.sagemath.org/question/37212/How to export a 3D plot to a jpg/png file (OSX)https://ask.sagemath.org/question/34559/how-to-export-a-3d-plot-to-a-jpgpng-file-osx/ Hi everybody, I've got some problems with saving/exporting images. This is my code:
var ('x y z')
#Define a 3d curve as the intersection of 2 surfaces
#(but not explicit in z so we must use implicit plots)
# Let's plot
xmin=-3; xmax=3; ymin=-1; ymax=5; zmin=-3; zmax=3;
# Axes
Ax=line3d(([xmin,0,0],[xmax,0,0]), thickness=2, color='red')
Ay=line3d(([0,ymin,0],[0,ymax,0]), thickness=2, color='blue')
Az=line3d(([0,0,zmin],[0,0,zmax]), thickness=2, color='green')
# Surfaces
S1=implicit_plot3d(y==x^2+z^2,(x,xmin,xmax),(y,ymin,ymax),(z,zmin,zmax), opacity=0.4, color='yellow')
S2=implicit_plot3d(z==y/2,(x,xmin,xmax),(y,ymin,ymax),(z,zmin,zmax), opacity=0.4, color='purple')
show(S1+S2+Ax+Ay+Az, aspect_ratio=[1,1,1])
I just wanted to execute the code, rotate the plot right from the graphics and export the image as a png file. This should by done by right-clicking on the plot and chosing export to png from the menu... Unfortunately, the output is a blank screen with just the string "Invalid JSmol request: saveFile"
Any suggestion, please?
I'm working with the OS X version, and I'm a total newbie...
Thanks in advice,
MauromaurosiriguMon, 22 Aug 2016 06:29:09 -0500https://ask.sagemath.org/question/34559/Insert image into Graphics objecthttps://ask.sagemath.org/question/32417/insert-image-into-graphics-object/ Is it possible to insert an image (let's say, a PNG file) into a Graphics object containing some plots?
I need to create a raster inset into a figure with the list_plot'ted curves.v_2eTue, 02 Feb 2016 06:37:32 -0600https://ask.sagemath.org/question/32417/How to rotate an external image in sagehttps://ask.sagemath.org/question/32181/how-to-rotate-an-external-image-in-sage/ I want to rotate an external image in sage. I know how to rotate a plot created on sage and how to load an external image and view it later, but i cant use de function rotate on an external image. When I try to rotate the image with "rotate" sage says that the object doesnt have such attribute. Does someone know how to do it?lauwiWed, 13 Jan 2016 04:36:47 -0600https://ask.sagemath.org/question/32181/Display a PNG image file in a worksheethttps://ask.sagemath.org/question/8968/display-a-png-image-file-in-a-worksheet/I've uploaded an image file (`DATA+'foo.png'`) into a notebook worksheet. How can I display it in the worksheet? I've tried using the statement
`show(DATA+'foo.png')`
but it just returns the file's path:
`'/home/sage/.sage/sage_notebook.sagenb/home/admin/18/data/foo.png'`TSchwennSat, 12 May 2012 10:08:10 -0500https://ask.sagemath.org/question/8968/Is there a way to insert a .png into a LaTex document?https://ask.sagemath.org/question/25523/is-there-a-way-to-insert-a-png-into-a-latex-document/ I'm trying to insert a picture of a graph I made for a project I'm working on and I would like to insert it into my final Latex file. Is there a way to do this on sagemath?
Thank you.kstdWed, 14 Jan 2015 20:50:34 -0600https://ask.sagemath.org/question/25523/how to transfer *.svg to *.gif or jepg?https://ask.sagemath.org/question/24594/how-to-transfer-svg-to-gif-or-jepg/ how to transfer *.svg to *.gif or jepg?cjshThu, 23 Oct 2014 05:04:33 -0500https://ask.sagemath.org/question/24594/How can I save an image from sage plot ?https://ask.sagemath.org/question/10002/how-can-i-save-an-image-from-sage-plot/I am working on a project that needs the graph image generated by sage to save to disk then that would be retrieved in the application. Here is the code I am writing for generating a Graph<br>
<br>
G=Graph({'a': {'c': 25, 'b': 26, 'e': 30, 'd': 35}, 'c': {'a': 25, 'b': 33, 'e':
27, 'd': 7}, 'b': {'a': 26, 'c': 33, 'e': 34, 'd': 7}, 'e': {'a': 30,
'c': 27, 'b': 34, 'd': 9}, 'd': {'a': 35, 'c': 7, 'b': 7, 'e': 9}})
G.weighted(True)
E = kruskal(G, check=True)
print E
tot=[]
kcost=0;totcost=0
for key in E:
tot.append((key[0],key[1]))
kcost=kcost+key[2]
rev=tot[::-1]
for key in rev:
tot.append((key[1],key[0]))
path=[]
tot1=[]
for key in E:
tot1.append((key[0],key[1]))
tot1.append((key[0],key[1]))
kcost=kcost+key[2]
for p in tot1:
if p[0] not in path:
path.append(p[0])
if p[1] not in path:
path.append(p[1])
print path
print tot1
kcost=totcost/2
print tot,totcost,kcost
N=Graph(E)
N.show()
N1=Graph(tot1)
N1.show()
N.show() and N1.show() will show the Graph describing Now I am facing error running the file and generating image and my image viewer gives me error as in this post of your Google + community I have posted
https://plus.google.com/u/0/113942220708315173370/posts/jScisbFzeDr
So I am Planning to save the image at my selected location and fetch the image from that Position.
for that I am using in my code and unsure where to supply a or how to save it Please suggest me how should I save the Images from show() method.
I am using Python2.7 does it require some additional package of sagemath.
N1=Graph(tot)
a=N1.show()
newimage=Image.new("RGB",(500,500),"white")
newimage.load()
newimage.save("out.png")Chitrank DixitMon, 08 Apr 2013 02:36:12 -0500https://ask.sagemath.org/question/10002/How quickly minimizing $M*x-v$ (numerically) ?https://ask.sagemath.org/question/10643/how-quickly-minimizing-mx-v-numerically/Let $v$ in $R^m$ and let $M$ be a matrix from $R^n$ to $R^m$, with $m>n$ big numbers.
I want to compute a vector $x$ in $R^n$ such that the norm of $M*x-v$ is minimal.
One way is to compute the projection $w$ of $v$ on the image of $M$.
For so, we can compute the projection $p$ on the image of $M$, as follows :
MTGS=M.transpose().gram_schmidt()[0] # it's orthogonalization, not orthonormalization
l=MTGS.rank()
U=[]
for i in range(l):
v=MTGS[i]
u=v/(v.norm())
L=list(u)
U.append(L)
N=matrix(m,l,U)
p=N.transpose()*N
Then:
w=p*v
x=M.solve_right(w)
This vector $x$ minimizes the norm of $M*x-v$, but this method is very expensive in time, because it computes $p$ and $w$, while I just need $x$.
> Is there another method, less expensive in time, for computing $x$ ?
**Remark** : I'm ok with numerical methods.
Sébastien PalcouxMon, 21 Oct 2013 13:03:37 -0500https://ask.sagemath.org/question/10643/How can I show any image in sage notebook via html?https://ask.sagemath.org/question/10627/how-can-i-show-any-image-in-sage-notebook-via-html/Hello!
I type in sage notebook 5.12 (linux mint 15 cinnamon):<br>
html("<img src='1.png'></img>")
If 1.png is placed in DATA path, my code works fine.<br>
When 1.png is placed in any other path, I can't do anything my code work.<br>
Is it possible to show any image in sage notebook via html code?<br>
I need html to create html output with images from my functions.<br>
Please help me. Thanks a lot!)AndreWinSun, 20 Oct 2013 00:25:10 -0500https://ask.sagemath.org/question/10627/high resolution image - matplotlibhttps://ask.sagemath.org/question/10334/high-resolution-image-matplotlib/Hi experts!
How can i generate matplotlib graphs in custom resolution (for example: 1020p)?
waiting for your answers.
Thanks a lot!mresimulatorTue, 09 Jul 2013 05:08:23 -0500https://ask.sagemath.org/question/10334/Problem showing imageshttps://ask.sagemath.org/question/9254/problem-showing-images/I am quite new to SAGE so I am probably asking something silly but some days of google search did not provide a simple answer to my question.
Using instructions from [this](http://blancosilva.wordpress.com/2010/12/15/image-processing-with-numpy-scipy-and-matplotlibs-in-sage/) website I created a small sage program:
from numpy import *
import scipy.ndimage
import matplotlib.image
import matplotlib.pyplot
img=matplotlib.image.imread(DATA+'dummy.png')
print 'Image dtype: %s'%(img.dtype)
print 'Image size: %6d'%(img.size)
print 'Image shape: %3dx%3d'%(img.shape[0],img.shape[1])
print 'Max value %1.2f at pixel %6d'%(img.max(),img.argmax())
print 'Min value %1.2f at pixel %6d'%(img.min(),img.argmin())
print 'Variance: %1.5f\nStandard deviation: %1.5f'%(img.var(),img.std())
where dummy.png is an existing PNG image that I loaded into the worksheet.
The script works perfectly and I get the required info out of it:
Image dtype: float32
Image size: 17335905
Image shape: 2305x2507
Max value 1.00 at pixel 1767
Min value 0.00 at pixel 2032962
Variance: 0.06310
Standard deviation: 0.25120
now if I want to actually see the picture everything fails. I tried to type:
img
show(img)
img.show
img.show()
My final goal was to overlay the image, a photo, with the plot resulting from an analysis to show the accuracy of the prediction. Does anyone know how to do that?
thanks,
mcirrimcirriMon, 20 Aug 2012 04:27:05 -0500https://ask.sagemath.org/question/9254/showing an external image in sage notbookhttps://ask.sagemath.org/question/9308/showing-an-external-image-in-sage-notbook/Is there an easy way to show an image stored in local drive (or a website) in sage notebook?
The only way I know is using matplotlib:
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
img=mpimg.imread('<location of image file')
plt.imshow(img)
frame = plt.gca()
frame.axes.get_xaxis().set_visible(False)
frame.axes.get_yaxis().set_visible(False)
plt.savefig("temp.png")
but, it is a roundabout way and shows the unecessary black border around the image. ebsSun, 09 Sep 2012 14:21:54 -0500https://ask.sagemath.org/question/9308/Call pure python code from SAGEhttps://ask.sagemath.org/question/8938/call-pure-python-code-from-sage/Dear all,
I want to move from matlab for my image processing tasks. Nevertheless, to load the file formats I use (SPIDER, MRC, etc..), I only have some python code. Is it possible to directly invoke such python code from SAGE?. If so.. how? (I have looked for a Python inteface, but no luck for SAGE invoking Python). If not.. what is the recommended workflow to program and publish my codes for the community?.
Thanks in advance!kankamusoMon, 30 Apr 2012 05:23:18 -0500https://ask.sagemath.org/question/8938/Is ther a way to capture images from a webcam?https://ask.sagemath.org/question/8911/is-ther-a-way-to-capture-images-from-a-webcam/HI i new here, i have experience programming Matlab and SCILAB and i want to know if SAGE can open a webcam take a pic and start an analisys.
THanks in advance
RodolfoCositomayorSat, 21 Apr 2012 06:44:26 -0500https://ask.sagemath.org/question/8911/Viewing Stereographic Projection of an Imagehttps://ask.sagemath.org/question/8824/viewing-stereographic-projection-of-an-image/I'm trying to write a program that takes an image and projects it onto a sphere that I can then view using 3dplot. I'm using pylab to read the image, numpy to put it into an array and then a stereographic projection to actually project it onto a sphere. I'm fairly certain the program is working correctly.
The problem I have is that 3dplot is not letting me view an image. The plot doesn't load. I tried the tachyon viewer, and I could get an image of my picture on a sphere, but I would prefer if I had the ability to rotate the sphere that 3dplot provides. Is there a better way to accomplish what I'm trying other than using pylab? I don't know much about other python imaging systems.
SeikishiSat, 24 Mar 2012 12:15:43 -0500https://ask.sagemath.org/question/8824/