laszukdawid / PyEMD

Python implementation of Empirical Mode Decompoisition (EMD) method
https://pyemd.readthedocs.io/
Apache License 2.0
867 stars 224 forks source link

BEMD failed to work #39

Closed issamMOUDNI closed 5 years ago

issamMOUDNI commented 5 years ago

Hi, Thank you for your great library it helps a lot. I'm trying to use BEMD method but i got the error below

NameError: name 'reconstruction' is not defined

Could you please help me to solve this.

This is the code i'm trying to execute.

from PyEMD import EMD2D , BEMD
from skimage import color
from skimage import io
import matplotlib.pyplot as plt
%matplotlib inline

img = color.rgb2gray(io.imread('img.jpg'))
bemd = BEMD()
IMFs_2D = bemd(img[:950])

The full error:

---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-65-c8c252320b0f> in <module>
      1 bemd = BEMD()
----> 2 IMFs_2D = bemd(img[:950])

~/Doctorat/segmentation/codes/lib/python3.6/site-packages/EMD_signal-0.2.6-py3.6.egg/PyEMD/BEMD.py in __call__(self, image, max_imf)
     53 
     54     def __call__(self, image, max_imf=-1):
---> 55         return self.bemd(image, max_imf=max_imf)
     56 
     57     def extract_max_min_spline(self, image, min_peaks_pos, max_peaks_pos):

~/Doctorat/segmentation/codes/lib/python3.6/site-packages/EMD_signal-0.2.6-py3.6.egg/PyEMD/BEMD.py in bemd(self, image, max_imf)
    222                 self.logger.debug("Iteration: %i", n)
    223 
--> 224                 min_peaks_pos, max_peaks_pos = self.find_extrema_positions(imf)
    225                 self.logger.debug("min_peaks_pos = %i  |  max_peaks_pos = %i", len(min_peaks_pos[0]), len(max_peaks_pos[0]))
    226                 if len(min_peaks_pos[0])>1 and len(max_peaks_pos[0])>1:

~/Doctorat/segmentation/codes/lib/python3.6/site-packages/EMD_signal-0.2.6-py3.6.egg/PyEMD/BEMD.py in find_extrema_positions(cls, image)
    104             Maxima positions.
    105         """
--> 106         min_peaks_pos = BEMD.extract_minima_positions(image)
    107         max_peaks_pos = BEMD.extract_maxima_positions(image)
    108         return min_peaks_pos, max_peaks_pos

~/Doctorat/segmentation/codes/lib/python3.6/site-packages/EMD_signal-0.2.6-py3.6.egg/PyEMD/BEMD.py in extract_minima_positions(cls, image)
    110     @classmethod
    111     def extract_minima_positions(cls, image):
--> 112         return BEMD.extract_maxima_positions(-image)
    113 
    114     @classmethod

~/Doctorat/segmentation/codes/lib/python3.6/site-packages/EMD_signal-0.2.6-py3.6.egg/PyEMD/BEMD.py in extract_maxima_positions(cls, image)
    115     def extract_maxima_positions(cls, image):
    116         seed_min = image - 1
--> 117         dilated = reconstruction(seed_min, image, method='dilation')
    118         cleaned_image = image - dilated
    119         return np.where(cleaned_image>0)[::-1]

NameError: name 'reconstruction' is not defined

Thank you for your support,

laszukdawid commented 5 years ago

Hey @issamMOUDNI,

Thanks for the PyEMD useful. It's always nice to hear from others :-)

Unfortunately, due to limited time and others project coming to priority, I decided a while back not to support bivariate/image decomposition. It's never what others expect and there's plenty of inefficient algorithms. It's simply a trouble that I'm unable to take.

So, forgive me, but I won't be able to help. The only reason why the code is still there is if anyone else wants to take the lead on it and contribute. Feel free to propose code change :-)

Having said all of that, the issue is because there was a problem with from skimage.morphology import reconstruction which means that you don't have skimage installed. To use BEMD and EMD2D you need to install packages from requirements-extra.txt (list).

Hope this helps, and sorry again for not supporting BEMD and EMD2D.

ElrondL commented 2 years ago

We need BEMD and EMD2D support 🥺