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.Wed, 25 Mar 2020 16:48:17 -0500Scaling imageshttps://ask.sagemath.org/question/50364/scaling-images/ Hi,
I am trying to figure out how to create say an 800 x 600 image that will be able to fit different size sheets of paper. Eventually I would like to expand this algorithm to include all the other screen resolutions. However, when Sage generates an image there is the boarder of white. So I have to go in and crop it out with image editing software. This then changes the pixel dimension. I would like to get a ratio of 1:1 between the m x n image and the image generated. I have figured out this ratio when dpi value is at 100, and it turns out that a dpi value of about 172 will get me really close to creating an image of 800 x 600. However, the actual image is roughly 795 x 596, and if I use 173 it turns out to be 801 x 600.
I am wondering if someone has already created an algorithm to print a 1:1 scale for screen resolution to printed image?nooniensoong97Wed, 25 Mar 2020 16:48:17 -0500https://ask.sagemath.org/question/50364/How to edit pixel values of color image in SageMath?https://ask.sagemath.org/question/43913/how-to-edit-pixel-values-of-color-image-in-sagemath/ I would like to change pixel values in a color [image](https://drive.google.com/file/d/1zyRvIUc1I9rC-NrU4SYjdbbPf8NOrQk0/view?usp=sharing) with Sagemath. I can do the same in python, but my program contains some parts which can not be done with python. Here are the codes for SageMath:
**MWE:**
from PIL import Image
img=Image.open('image.pgm')
pxl=img.load()
#pxls=img.getdata()
print pxl[0,0]
When I compile thse codes with sage, error occurs :
" File "smmm.sage.py", line 8, in <module>
print pxl[_sage_const_0 ,_sage_const_0 ]
TypeError: an integer is required
"
How can I fix this?BSFUThu, 11 Oct 2018 06:33:40 -0500https://ask.sagemath.org/question/43913/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/image processing in notebook serverhttps://ask.sagemath.org/question/40181/image-processing-in-notebook-server/I have a local notebook server and I'd like to be able to use the image manipulation modules from scipy. They seem to import just fine, but I never get any images, only what appear to be commands.
import pylab
from scipy import misc
A = misc.face()
pylab.imshow(A)
Outputs
AxesImage(80,48;496x384)
Do I need some additional configuration, or a plugin to make it work?AllenSat, 16 Dec 2017 02:28:07 -0600https://ask.sagemath.org/question/40181/Read bitmap into 2D array?https://ask.sagemath.org/question/11069/read-bitmap-into-2d-array/How can I read the bitmap image file into a two-dimensional list of numbers?v_2eWed, 11 Jun 2014 20:48:23 -0500https://ask.sagemath.org/question/11069/How to load a local image from cloud.sagemath?https://ask.sagemath.org/question/10108/how-to-load-a-local-image-from-cloudsagemath/Hello, I tried naively to load an image in a worksheet from my cloud.sagemath account. Something like:
from scipy import ndimage as nd
image=nd.imread('~/path/to/image.jpg')
and of course that failed. Is there a way to do that?
thank you
jpjeanpatThu, 09 May 2013 07:26:54 -0500https://ask.sagemath.org/question/10108/Image processinghttps://ask.sagemath.org/question/9911/image-processing/Dear all,
I have question about manipulating image in Sage. Here is some example.
import pylab
img=pylab.imread(DATA+'lena.png')
Img is now array with float elements. But I want to add some shapes on this image like circle, rectangle, polygon etc, but c=Circle, b=Rectangle and a=Polygon are object of some clases so if I want to do something like this show(img+c) or show(img+b) it is not allowed.
Another question is: How I can put circle on my position (position is corner of image) because Img is array so I don't know where new row start.
Is there some simple way to do this?
Thank you in advance
beginnerThu, 14 Mar 2013 08:39:31 -0500https://ask.sagemath.org/question/9911/image processing in sagehttps://ask.sagemath.org/question/7891/image-processing-in-sage/Dear all,
I have problems to call `scipy.ndimage.binary_opening`. Code, output and error messages in sage are as follows...
**SAGE:**
from numpy import *
import scipy.ndimage
import matplotlib.image
import matplotlib.pyplot
img=matplotlib.image.imread(DATA+'NbW-STEM.png')
type(img)
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())
**OUTPUT:**
Image dtype: float32
Image size: 261075
Image shape: 295x295
Max value 1.00 at pixel 226320
Min value 0.00 at pixel 17109
Variance: 0.02580
Standard deviation: 0.16062
**SAGE:**
BWatoms=img>0.62
BWatoms=scipy.ndimage.binary_opening(BWatoms,structure=ones((2,2)))
**ERROR MESSAGE:**
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "_sage_input_27.py", line 10, in <module>
exec compile(u'open("___code___.py","w").write("# -*- coding: utf-8 -*-\\n" + _support_.preparse_worksheet_cell(base64.b64decode("QldhdG9tcz1pbWc+MC42MgpCV2F0b21zPXNjaXB5Lm5kaW1hZ2UuYmluYXJ5X29wZW5pbmcoQldhdG9tcyxzdHJ1Y3R1cmU9b25lcygoMiwyKSkp"),globals())+"\\n"); execfile(os.path.abspath("___code___.py"))
File "", line 1, in <module>
File "/tmp/tmpaXpo0G/___code___.py", line 4, in <module>
exec compile(u'BWatoms=scipy.ndimage.binary_opening(BWatoms,structure=ones((_sage_const_2 ,_sage_const_2 )))
File "", line 1, in <module>
File "/home/ottom/Documents/sage_build/sage-4.6.1/local/lib/python2.6/site-packages/scipy/ndimage/morphology.py", line 646, in binary_opening
origin)
File "/home/ottom/Documents/sage_build/sage-4.6.1/local/lib/python2.6/site-packages/scipy/ndimage/morphology.py", line 394, in binary_erosion
output, border_value, origin, 0, brute_force)
File "/home/ottom/Documents/sage_build/sage-4.6.1/local/lib/python2.6/site-packages/scipy/ndimage/morphology.py", line 229, in _binary_erosion
raise RuntimeError, 'structure rank must equal input rank'
RuntimeError: structure rank must equal input rank
This code was also tested on the sage-online server (alpha), which failed as well. The code worked fine with Enthought 6.2-2 (pylab-mode). Any suggestions are welcome.
All the best
Otto
ottomMon, 24 Jan 2011 02:24:58 -0600https://ask.sagemath.org/question/7891/Mathematical Morphology?https://ask.sagemath.org/question/9321/mathematical-morphology/Is there a recommended package for Sage (or simply for Python) to do morphological image processing -- for instance, dilation, erosion, thinning, opening, closing, skeleton generation -- and related transformations?Ralph DratmanSat, 15 Sep 2012 14:34:07 -0500https://ask.sagemath.org/question/9321/