Trying to plot an image in python (using scipy and numpy) - python

I'm trying to run this code:
http://forumbilder.se/H8CIL/skarmavbild-2018-10-08-kl-21-22-19
so I change it to this one:
and then I got this:
http://forumbilder.se/H8CIL/skarmavbild-2018-10-08-kl-21-22-47
What's wrong? I'm a newbie, and fyi, I'm only have anaconda installed to my Python 3.6.6 .
Regards,
--
and in code:
from skimage import data
photo_data = misc.imageio('./wifire/sd-3layers.jpg')
type(photo_data)
and i get this error:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-9-c8186ae7b8e9> in <module>()
1 from skimage import data
2
----> 3 photo_data = misc.imageio('./wifire/sd-3layers.jpg')
4
5 type(photo_data)
AttributeError: module 'scipy.misc' has no attribute 'imageio'
So I change it to:

You have to import imageio. You might have to install the library if you don't have it yet (on your terminal):
pip install imageio
(If you don't have pip install yet, you can do on your terminal sudo easy_install pip, see here: How do I install pip on macOS or OS X?)
And then your code to use read the image with imageio:
import imageio
im = imageio.imread('./wifire/sd-3layers.jpg')
type(im)
To display your image, you can use visvis library (https://imageio.readthedocs.io/en/stable/examples.html). Then you total code would be:
import imageio
import visvis as vv
im = imageio.imread('./wifire/sd-3layers.jpg')
vv.imshow(im)

Related

python colab issue with wand library

greetings ---
hey gues , I have an a problem with google.colab when I want to run this code :
# Import Image from wand.image module
from wand.image import Image
# Read image using Image() function
with Image(filename ="/content/Hand.jpeg") as img:
# Generate noise image using spread() function
img.noise("poisson", attenuate = 0.9)
img.save(filename ="noise_hand.jpeg")
the issue is with this command :
from wand.image import Image
it keep saying :
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-2-c8294d82387e> in <module>()
1 # Import Image from wand.image module
----> 2 from wand.image import Image
this issue only appears in colab, I mean, for example, it works fine with Microsoft visual studio.
pls guess someone help me to fix this problem, and thanks in advance
note: I already installed and imported the wand library
Try installing ImageMagick by running these in a cell before your code.
!sudo apt install imagemagick
!pip install wand

Can't from PIL import Image?

I have tried to install pillow version 7.0.0 but get the following error below. Please suggest a solution.
ImportError Traceback (most recent call last)
<ipython-input-32-b7f01c2f8cfe> in <module>
----> 1 from PIL import Image
~\Anaconda3\envs\streamlined\lib\site-packages\PIL\Image.py in <module>
42 # PILLOW_VERSION was removed in Pillow 7.0.0.
43 # Use __version__ instead.
---> 44 from . import ImageMode, TiffTags, UnidentifiedImageError, __version__, _plugins
45 from ._binary import i8, i32le
46 from ._util import deferred_error, isPath
ImportError: cannot import name 'UnidentifiedImageError' from 'PIL' (unknown location)
This looks like a library that you are using, or that is interfacing with PIL/Pillow was built for a previous version, so you either need to update the library/code calling PIL/Pillow, or install the version of Pillow that your library/code is written for.
Example of how to install pillow version 5.0.0
$ pip install pillow==5.0.0

How can I Fix an ImportError

So I am stuck on how can I fix the import error for imresize. I installed all the things I needed like installing Pillow but I haven't been able to find a solution. Also the code that I trying to run is from this github link https://github.com/CSAILVision/IBD
Also side note I do not own this code nor was not the original arthor of it. This is for a research project that I am apart of. In addition I try asked the original arthor with a fix but haven't heard back from them at all.
Installing Pillow, Replacing with code: from scipy.misc.pilutil import imread, installing Pillow-3.3.1-cp27-cp27m-win32.whl, Unninstall Pil and installing Pillow, Reinstalling Pillow.
from util.image_operation import *
from PIL import Image
import numpy as np
from imageio import imresize, imread
from visualize.plot import random_color
from torch.autograd import Variable as V
import torch
I expect it to run but print out the image but it doesn't.
Traceback (most recent call last):
File "test.py", line 4, in <module>
from loader.model_loader import loadmodel
File "/home/joshuayun/Desktop/IBD/loader/model_loader.py", line 5, in <module>
from util.feature_operation import hook_feature, hook_grad
File "/home/joshuayun/Desktop/IBD/util/feature_operation.py", line 6, in <module>
from imageio import imresize, imread, imsave
ImportError: cannot import name 'imresize'
If you want to work with the code as is, i would recommend creating a new environment, and installing an old version of scipy (0.19.1 should do the trick). In your new environment, assuming you are using conda, do:
conda install scipy==0.19.1
If you use pip instead:
pip install scipy==0.19.1
Since scipy 1.3.0rc1 resize has been removed.
I had the same problem, I had scipy 1.4. I did the following and it worked -
pip install scipy==1.1.0

Getting numpy error when using azureml-sdk

hy I followed the installation instructions here
and installed with
pip install --upgrade azureml-sdk[notebooks,automl] azureml-dataprep --ignore-installed PyYAML
It seem to work but a simple
import azureml.core
azureml.core.VERSION
Throws me a numpy error
> AttributeError Traceback (most recent call
> last) <ipython-input-3-08b704cd5542> in <module>
> ----> 1 import azureml.core
> 2 azureml.core.VERSION
c:\users\werth\appdata\local\continuum\anaconda3\envs\azuresdk\lib\site-packages\azureml\core\__init__.py in <module>
4
5 """Setup file for core package."""
----> 6 from azureml.core.workspace import Workspace
7 from azureml.core.experiment import Experiment
8 from azureml.core.runconfig import RunConfiguration
... I did not include the total traceback as it is apparently a Azure import problem.
AttributeError: type object 'numpy.ndarray' has no attribute '__array_function__'
It seems that the workspace has a problem. But I cannot think why. The Notebook is in a subfolder of the working directory. Numpy is installed.
If you would have an idea I would be thankfull.
Hi greatest Floridaman,
the answer is simple. During the installation of the azureml-train-automl 1.0.8 package, the numpy package needs to be maximum at version 1.15.0
So just downgrade numpy to that version
conda install numpy=1.15.0

import error OpenCV on Jupyter Notebook (but it works in Ipython on Terminal..)

I'm having an interesting error where I could import cv2 in Ipython on Terminal but cannnot import the library on Jupyter notebook. I checked the kernel but I'm using the same kernel (Anaconda python2.7)
Would someone has any idea how to fix this?
Error:
ImportErrorTraceback (most recent call last)
<ipython-input-2-52da0154cfe4> in <module>()
----> 1 import cv2
2 import numpy as np
ImportError: No module named cv2
$import os
$os.sys.path
['',
'/Users/kn/anaconda2/envs/python2/lib/python27.zip',
'/Users/kn/anaconda2/envs/python2/lib/python2.7',
'/Users/kn/anaconda2/envs/python2/lib/python2.7/plat-darwin',
'/Users/kn/anaconda2/envs/python2/lib/python2.7/plat-mac',
'/Users/kn/anaconda2/envs/python2/lib/python2.7/plat-mac/lib-scriptpackages',
'/Users/kn/anaconda2/envs/python2/lib/python2.7/lib-tk',
'/Users/kn/anaconda2/envs/python2/lib/python2.7/lib-old',
'/Users/kn/anaconda2/envs/python2/lib/python2.7/lib-dynload',
'/Users/kn/anaconda2/envs/python2/lib/python2.7/site-packages',
'/Users/kn/anaconda2/envs/python2/lib/python2.7/site-packages/Sphinx-1.4.6-py2.7.egg',
'/Users/kn/anaconda2/envs/python2/lib/python2.7/site-packages/aeosa',
'/Users/kn/anaconda2/envs/python2/lib/python2.7/site-packages/setuptools-27.2.0-py2.7.egg',
'/Users/kn/anaconda2/envs/python2/lib/python2.7/site-packages/IPython/extensions',
'/Users/kn/.ipython']
$which python
/Users/kn/anaconda2/envs/python2/bin/python
Create a one-line opencv.pth file under /Users/kn/anaconda2/lib/python2.7/site-packages.
The content of that file is like:
/usr/local/opt/opencv3/lib/python2.7/site-packages
This will append the opencv3 path under all conda environments permanently. I think it's better than just make cv2 available for python2 environment.

Categories

Resources