laszukdawid / PyEMD

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

EMD2D - not working with difference width and heigh. #25

Closed trongan93 closed 6 years ago

trongan93 commented 6 years ago

Only can be working with the same width and height. With case difference width(row) and heigh(col), it cannot be working.

laszukdawid commented 6 years ago

Hi Bui, Thanks for reporting the issue. Any chance you could share the code that you tried and the received error?

On Thu, May 24, 2018, 21:23 Bui Trong-An notifications@github.com wrote:

Only can be working with the same width and height. With case difference width(row) and heigh(col), it cannot be working.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/laszukdawid/PyEMD/issues/25, or mute the thread https://github.com/notifications/unsubscribe-auth/AK7Vq8L4Sb8_TNVAtA3lHggMWElEyPB9ks5t14dagaJpZM4UNWIz .

trongan93 commented 6 years ago
rgbInputImage = cv2.imread('img-test/testimage-2.jpg')
hsvInputImage = cv2.cvtColor(rgbInputImage, cv2.COLOR_BGR2HSV)
hue, sat, val = hsvInputImage[:,:,0], hsvInputImage[:,:,1], hsvInputImage[:,:,2]
emd2d = EMD2D()
IMFs = emd2d.emd(hue, max_imf=4)

With this coding, when my input is image with height x width is 576 x 576 or 800 x 800 it will ok, but with size is 576 x 800, it shows error:

File "2d-hhtTest.py", line 40, in IMFs = emd2d.emd(hue, max_imf=4) "lib\site-packages\emd_signal-0.2.5-py3.6.egg\PyEMD\EMD2d.py", line 322, in emd "lib\site-packages\emd_signal-0.2.5-py3.6.egg\PyEMD\EMD2d.py", line 81, in extract_max_min_spline "lib\site-packages\emd_signal-0.2.5-py3.6.egg\PyEMD\EMD2d.py", line 150, in spline_points "\lib\site-packages\scipy\interpolate\fitpack2.py", line 1041, in init eps=eps,lwrk2=1) ValueError: failed to create intent(cache|hide)|optional array-- must have defined dimensions but got (-1340704942,)

Thank.

zzyno1 commented 6 years ago

EMD for image, if the image size is 13001300 pixels, it works well, but it does not work when the image size is 14001400 pixels or large, the error message:
" ValueError: failed to create intent(cache|hide)|optional array-- must have defined dimensions but got (-2044085130,)",

laszukdawid commented 6 years ago

Hi @zzyno1, Apologies for such late reply. Based on your log it doesn't seem to be related to non-square images. Actually, this is more an issue that you're requesting too big image. Behind the scenes the EMD2D is dealing with edge conditions through mirroring to all directions. This makes the request to be 9 times bigger than the input. In case when the input is 1400x1400 px the actual allocation requires 9x1400x1400 which seems to be too big. This is a separate issue. Could you please create new one?

laszukdawid commented 6 years ago

As for the non square images I'm actually unable to reproduce the issue. Googling the issue it seems to be related to the numerical libraries used in the scipy. I'm investigating this issue. Not sure how fast I'll be able to provide updates.

laszukdawid commented 6 years ago

@trongan93 & @zzyno1, The sad story behind this is that indeed I'm observing problems when using EMD2D or BEMD on large or complex images. This seems to be related mainly to poor extrema detection and their handling. The algorithms used for detection (through erosion or checking surrounding) will return too many extrema for the RBF spline to handle leading to Out of Memory exception.

This was meant to be an easy extension which would hopefully be useful. Unfortunately EMD2D/BEMD are the extensions that disappoint (too often). Due to lack of time and shift in interest I'm unable to maintain/fix them.

Since it might be useful to someone, I've decided to keep the code in the package, although warnings were added. Please feel free to propose modifications.

One of the possibilities, which I'm not sure if it will become real, is to add binding to this C++ code. But this is a big maybe and please don't expect it soon.