Iklan1

Friday, July 26, 2019

TIPS : Scikit-image error Viewer requires Qtwarn

Berikut adalah error warning yang muncul pada saat kita ingin menampilkan gambar dari scikit-image :

UserWarning: Viewer requires Qtwarn('Viewer requires Qt')

Langkah menampilkan Image atau gambar dari scikit-image :
1. Install PyQt yang sesuai dengan Scikit-image-nya
D:\tesF>pip install PyQt5
Collecting PyQt5
  Using cached https://files.pythonhosted.org/packages/c9/e3/302602473ad0997d9a86b69324350bcfd13ac137ffa76806d6f58bda1e1d/PyQt5-5.13.0-5.13.0-cp35.cp36.cp37.cp38-none-win32.whl
Collecting PyQt5_sip<13,>=4.19.14 (from PyQt5)
  Downloading https://files.pythonhosted.org/packages/38/10/4ee0be6337eddcdf9070659b314416c66b73198505d61995684ff5538e69/PyQt5_sip-4.19.18-cp37-none-win32.whl (44kB)
     |████████████████████████████████| 51kB 1.7MB/s
Installing collected packages: PyQt5-sip, PyQt5
Successfully installed PyQt5-5.13.0 PyQt5-sip-4.19.18

2. tes dengan sample program ini
from skimage import data
from skimage.viewer import ImageViewer

image = data.coins()
viewer = ImageViewer(image)
viewer.show()

HASIL :

Akan muncul gambar coin tersebut.


Akan menampilkan gambar dan histogram :

from skimage import data
from skimage.exposure import histogram
from skimage.viewer import ImageViewer
from skimage.viewer.plugins.lineprofile import LineProfile
image = data.coins()
viewer = ImageViewer(image)
viewer += LineProfile(viewer)
overlay, data = viewer.show()[0]

Thursday, July 25, 2019

TIPS: Error saat import skimage library dari scikit-image

scikit-image adalah paket pengolah gambar Python yang bekerja dengan array numpy. Paket ini diimpor sebagai skimage.

Error muncul pada saat kita meng-import library skimage.

Berikut langkah-langkah memperbaiki error tersebut.

C:\WINDOWS\system32>python
Python 3.7.4 (tags/v3.7.4:e09359112e, Jul  8 2019, 19:29:22) [MSC v.1916 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import skimage
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\pc-name\AppData\Roaming\Python\Python37\site-packages\skimage\__init__.py", line 127, in <module>
    from .util.dtype import (img_as_float32,
  File "C:\Users\pc-name\AppData\Roaming\Python\Python37\site-packages\skimage\util\__init__.py", line 12, in <module>
    from ._montage import montage
  File "C:\Users\pc-name\AppData\Roaming\Python\Python37\site-packages\skimage\util\_montage.py", line 2, in <module>
    from .. import exposure
  File "C:\Users\pc-name\AppData\Roaming\Python\Python37\site-packages\skimage\exposure\__init__.py", line 1, in <module>
    from .exposure import histogram, equalize_hist, \
  File "C:\Users\pc-name\AppData\Roaming\Python\Python37\site-packages\skimage\exposure\exposure.py", line 3, in <module>
    from ..color import rgb2gray
  File "C:\Users\pc-name\AppData\Roaming\Python\Python37\site-packages\skimage\color\__init__.py", line 1, in <module>
    from .colorconv import (convert_colorspace,
  File "C:\Users\pc-name\AppData\Roaming\Python\Python37\site-packages\skimage\color\colorconv.py", line 55, in <module>
    from scipy import linalg
  File "C:\Users\pc-name\AppData\Local\Programs\Python\Python37-32\lib\site-packages\scipy\linalg\__init__.py", line 195, in <module>
    from .misc import *
  File "C:\Users\pc-name\AppData\Local\Programs\Python\Python37-32\lib\site-packages\scipy\linalg\misc.py", line 5, in <module>
    from .blas import get_blas_funcs
  File "C:\Users\pc-name\AppData\Local\Programs\Python\Python37-32\lib\site-packages\scipy\linalg\blas.py", line 214, in <module>
    from scipy.linalg import _fblas
ImportError: DLL load failed: The specified module could not be found.

Langkah Pertama :

C:\WINDOWS\system32>pip uninstall scipy
Uninstalling scipy-1.3.0:
  Would remove:
    c:\users\pc-name\appdata\local\programs\python\python37-32\lib\site-packages\scipy-1.3.0.dist-info\*
    c:\users\pc-name\appdata\local\programs\python\python37-32\lib\site-packages\scipy\*
Proceed (y/n)? y
  Successfully uninstalled scipy-1.3.0
Langkah Kedua :
C:\WINDOWS\system32>pip uninstall scikit-image
Uninstalling scikit-image-0.15.0:
  Would remove:
    c:\users\pc-name\appdata\local\programs\python\python37-32\lib\site-packages\scikit_image-0.15.0.dist-info\*
    c:\users\pc-name\appdata\local\programs\python\python37-32\lib\site-packages\skimage\*
    c:\users\pc-name\appdata\local\programs\python\python37-32\scripts\skivi.exe
Proceed (y/n)? y
  Successfully uninstalled scikit-image-0.15.0
Langkah Ketiga :
C:\WINDOWS\system32>pip install scikit-image
Collecting scikit-image
  Downloading https://files.pythonhosted.org/packages/68/49/46dc899a804fc4ed19f50708c64bcc6e7323529c960721dfe935c279f933/scikit_image-0.15.0-cp37-none-win32.whl (24.8MB)
     |████████████████████████████████| 24.8MB 6.4MB/s
Requirement already satisfied: imageio>=2.0.1 in c:\users\pc-name\appdata\local\programs\python\python37-32\lib\site-packages (from scikit-image) (2.5.0)
Requirement already satisfied: PyWavelets>=0.4.0 in c:\users\pc-name\appdata\local\programs\python\python37-32\lib\site-packages (from scikit-image) (1.0.3)
Requirement already satisfied: networkx>=2.0 in c:\users\pc-name\appdata\local\programs\python\python37-32\lib\site-packages (from scikit-image) (2.3)
Requirement already satisfied: pillow>=4.3.0 in c:\users\pc-name\appdata\local\programs\python\python37-32\lib\site-packages (from scikit-image) (6.1.0)
Requirement already satisfied: numpy in c:\users\pc-name\appdata\local\programs\python\python37-32\lib\site-packages (from imageio>=2.0.1->scikit-image) (1.16.4)
Requirement already satisfied: decorator>=4.3.0 in c:\users\pc-name\appdata\local\programs\python\python37-32\lib\site-packages (from networkx>=2.0->scikit-image) (4.4.0)
Installing collected packages: scikit-image
Successfully installed scikit-image-0.15.0

Langkah Keempat :
C:\WINDOWS\system32>pip install scipy
Collecting scipy
  Downloading https://files.pythonhosted.org/packages/be/cc/6f7842a4d9aa7f51155f849185631e1201df255742de84d724ac33bff723/scipy-1.3.0-cp37-cp37m-win32.whl (27.1MB)
     |████████████████████████████████| 27.1MB 6.4MB/s
Requirement already satisfied: numpy>=1.13.3 in c:\users\pc-name\appdata\local\programs\python\python37-32\lib\site-packages (from scipy) (1.16.4)
Installing collected packages: scipy
Successfully installed scipy-1.3.0

HASIL, Berikut hasil eksekusi script dari command prompt, jika tidak ada error berarti proses intalasi kamu berhasil

C:\WINDOWS\system32>python
Python 3.7.4 (tags/v3.7.4:e09359112e, Jul  8 2019, 19:29:22) [MSC v.1916 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> import skimage
>>> from skimage import data
>>> coins = data.coins()
>>> hist, hist_centers = histogram(coins)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'histogram' is not defined
>>> from skimage.exposure import histogram
>>> hist, hist_centers = histogram(coins)
>>> from skimage.feature import canny
>>> edges = canny(coins/255.)
>>> from scipy import ndimage as ndi
>>> fill_coins = ndi.binary_fill_holes(edges)
>>> label_objects, nb_labels = ndi.label(fill_coins)
>>> sizes = np.bincount(label_objects.ravel())
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'np' is not defined
>>> from scipy import ndimage as ndi
>>> fill_coins = ndi.binary_fill_holes(edges)
>>> import numpy
>>> fill_coins = ndi.binary_fill_holes(edges)
>>> sizes = np.bincount(label_objects.ravel())
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'np' is not defined
>>> import numpy as np
>>> sizes = np.bincount(label_objects.ravel())
>>> mask_sizes = sizes > 20
>>> mask_sizes[0] = 0
>>> coins_cleaned = mask_sizes[label_objects]
>>> markers = np.zeros_like(coins)
>>> markers[coins < 30] = 1
>>> markers[coins > 150] = 2
>>> from skimage.filters import sobel
>>> elevation_map = sobel(coins)
>>> markers = np.zeros_like(coins)
>>> markers[coins < 30] = 1
>>> markers[coins > 150] = 2
>>> from skimage.morphology import watershed
>>> segmentation = watershed(elevation_map, markers)
>>> segmentation = ndi.binary_fill_holes(segmentation - 1)
>>> labeled_coins, _ = ndi.label(segmentation)

catatan :
C:\WINDOWS\system32>python -V
Python 3.7.4

C:\WINDOWS\system32>pip -V
pip 19.1.1 from c:\users\pc-name\appdata\local\programs\python\python37-32\lib\site-packages\pip (python 3.7)

script pythonnya :

from skimage import data
from skimage.exposure import histogram
from scipy import ndimage as ndi
import numpy as np

coins = data.coins()
hist, hist_centers = histogram(coins)
from skimage.feature import canny
edges = canny(coins/255.)
fill_coins = ndi.binary_fill_holes(edges)
label_objects, nb_labels = ndi.label(fill_coins)
sizes = np.bincount(label_objects.ravel())
mask_sizes = sizes > 20
mask_sizes[0] = 0
coins_cleaned = mask_sizes[label_objects]
markers = np.zeros_like(coins)
markers[coins < 30] = 1
markers[coins > 150] = 2
from skimage.filters import sobel
elevation_map = sobel(coins)
markers = np.zeros_like(coins)
markers[coins < 30] = 1
markers[coins > 150] = 2
from skimage.morphology import watershed
segmentation = watershed(elevation_map, markers)
segmentation = ndi.binary_fill_holes(segmentation - 1)
labeled_coins, _ = ndi.label(segmentation)


Sunday, July 21, 2019

TIPS : Install Pip Python, Scikit Image Pada Windows

Install scikit_image pada windows :

software yang dibutuhkan
python
pip (peng-install paket python)untuk menginstal scikit_image
python package scikit_image yang sesuai versi python
python package scipy yang sesuai versi python

Jika setelah install pyhton command pip tidak bekerja
D:\Download>pip install scikit_image-0.15.0-cp38-cp38m-win_amd64.whl
scikit_image-0.15.0-cp38-cp38m-win_amd64.whl is not a supported wheel on this platform.
You are using pip version 19.0.3, however version 19.1.1 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.
lakukan upgrade

D:\Download>python -m pip install --upgrade pip
Collecting pip
  Downloading https://files.pythonhosted.org/packages/5c/e0/be401c003291b56efc55aeba6a80ab790d3d4cece2778288d65323009420/pip-19.1.1-py2.py3-none-any.whl (1.4MB)
    100% |████████████████████████████████| 1.4MB 5.8MB/s
Installing collected packages: pip
  Found existing installation: pip 19.0.3
    Uninstalling pip-19.0.3:
      Successfully uninstalled pip-19.0.3
Successfully installed pip-19.1.1

jika sudah upgrade muncul error

D:\Download>pip install scikit_image-0.15.0-cp38-cp38m-win_amd64.whl
ERROR: scikit_image-0.15.0-cp38-cp38m-win_amd64.whl is not a supported wheel on this platform.

lakukan dengan get-py linknya di https://bootstrap.pypa.io/get-pip.py
D:\Download>python get-pip.py
Collecting pip
  Using cached https://files.pythonhosted.org/packages/5c/e0/be401c003291b56efc55aeba6a80ab790d3d4cece2778288d65323009420/pip-19.1.1-py2.py3-none-any.whl
Collecting wheel
  Downloading https://files.pythonhosted.org/packages/bb/10/44230dd6bf3563b8f227dbf344c908d412ad2ff48066476672f3a72e174e/wheel-0.33.4-py2.py3-none-any.whl
Installing collected packages: pip, wheel
  Found existing installation: pip 19.1.1
    Uninstalling pip-19.1.1:
      Successfully uninstalled pip-19.1.1
Successfully installed pip-19.1.1 wheel-0.33.4

jika masih muncul

D:\Download>pip install scipy-1.3.0-cp37-cp37m-win_amd64.whl
ERROR: scipy-1.3.0-cp37-cp37m-win_amd64.whl is not a supported wheel on this platform.

lakukan instal scipy yang sesuai paket pyhton-nya dan platformnya (32 atau 64 bit)
Processing d:\download\scipy-1.3.0-cp37-cp37m-win32.whl
Collecting numpy>=1.13.3 (from scipy==1.3.0)
  Downloading https://files.pythonhosted.org/packages/07/46/656c25b39fc152ea525eef14b641993624a6325a8ae815b200de57cff0bc/numpy-1.16.4-cp37-cp37m-win32.whl (10.0MB)
     |████████████████████████████████| 10.0MB 544kB/s
Installing collected packages: numpy, scipy
Successfully installed numpy-1.16.4 scipy-1.3.0

D:\Download>pip install scikit_image-0.15.0-cp37-cp37m-win32.whl
Processing d:\download\scikit_image-0.15.0-cp37-cp37m-win32.whl
Collecting imageio>=2.0.1 (from scikit-image==0.15.0)
  Downloading https://files.pythonhosted.org/packages/af/0a/943c965d372dae0b1f1482677d29030ab834351a61a9a632fd62f27f1523/imageio-2.5.0-py3-none-any.whl (3.3MB)
     |████████████████████████████████| 3.3MB 2.2MB/s
Collecting pillow>=4.3.0 (from scikit-image==0.15.0)
  Downloading https://files.pythonhosted.org/packages/a1/db/d855fe2625bf3fee24b0d6138b6d10ebaee9a36b104fa77b71713c1f669f/Pillow-6.1.0-cp37-cp37m-win32.whl (1.7MB)
     |████████████████████████████████| 1.8MB ...
Collecting networkx>=2.0 (from scikit-image==0.15.0)
  Downloading https://files.pythonhosted.org/packages/85/08/f20aef11d4c343b557e5de6b9548761811eb16e438cee3d32b1c66c8566b/networkx-2.3.zip (1.7MB)
     |████████████████████████████████| 1.8MB ...
Collecting PyWavelets>=0.4.0 (from scikit-image==0.15.0)
  Downloading https://files.pythonhosted.org/packages/e2/21/76b982c168b728dceed500ae716ac0433989e21ceeaddae184c98ca20fb1/PyWavelets-1.0.3-cp37-none-win32.whl (4.1MB)
     |████████████████████████████████| 4.1MB 6.4MB/s
Requirement already satisfied: numpy in c:\users\iocn-2017-pc-025\appdata\local\programs\python\python37-32\lib\site-packages (from imageio>=2.0.1->scikit-image==0.15.0) (1.16.4)
Collecting decorator>=4.3.0 (from networkx>=2.0->scikit-image==0.15.0)
  Downloading https://files.pythonhosted.org/packages/5f/88/0075e461560a1e750a0dcbf77f1d9de775028c37a19a346a6c565a257399/decorator-4.4.0-py2.py3-none-any.whl
Building wheels for collected packages: networkx
  Building wheel for networkx (setup.py) ... done
  Stored in directory: C:\Users\IOCN-2017-PC-025\AppData\Local\pip\Cache\wheels\de\63\64\3699be2a9d0ccdb37c7f16329acf3863fd76eda58c39c737af
Successfully built networkx
Installing collected packages: pillow, imageio, decorator, networkx, PyWavelets, scikit-image
Successfully installed PyWavelets-1.0.3 decorator-4.4.0 imageio-2.5.0 networkx-2.3 pillow-6.1.0 scikit-image-0.15.0

Semoga bermanfaat. Thanks