deforum-art / deforum-stable-diffusion

https://deforum.github.io/
Other
2.2k stars 385 forks source link

skimage.exposure.match_histograms(multichannel=) argument is deprecated #270

Open rajb245 opened 1 year ago

rajb245 commented 1 year ago

See here https://github.com/deforum-art/deforum-stable-diffusion/blob/main/helpers/colors.py#L10-L15

The API in scikit image has moved on from using multichannel= as an argument to skimage.exposure.match_histograms. It was deprecated but available in skimage 0.19, removed in 0.20, and we're on 0.21 as of today. On colab this is fine because the default instance you get has a 0.19.3 scikit-image:

!pip show scikit-image
Name: scikit-image
Version: 0.19.3
Summary: Image processing in Python
Home-page: https://scikit-image.org/
Author: 
Author-email: 
License: Modified BSD
Location: /usr/local/lib/python3.10/dist-packages
Requires: imageio, networkx, numpy, packaging, pillow, PyWavelets, scipy, tifffile
Required-by: albumentations, imgaug

The new way is to use the channel_axis argument. It does not break things on colab (because channel_axis is supported and preferred over multichannel in 0.19) and is the only way forward for newer scikit-image version. See patch below. I don't want to fork on gh, make a branch, fix, and file an MR, etc., someone with write-privileges just commit these few lines, thanks! I'll begrudgingly do all this if I have to, let me know.

diff --git a/helpers/colors.py b/helpers/colors.py
index 6ec81e1..638809c 100644
--- a/helpers/colors.py
+++ b/helpers/colors.py
@@ -7,10 +7,10 @@ def maintain_colors(prev_img, color_match_sample, mode):
     elif mode == 'Match Frame 0 HSV':
         prev_img_hsv = cv2.cvtColor(prev_img, cv2.COLOR_RGB2HSV)
         color_match_hsv = cv2.cvtColor(color_match_sample, cv2.COLOR_RGB2HSV)
-        matched_hsv = match_histograms(prev_img_hsv, color_match_hsv, multichannel=True)
+        matched_hsv = match_histograms(prev_img_hsv, color_match_hsv, channel_axis=-1)
         return cv2.cvtColor(matched_hsv, cv2.COLOR_HSV2RGB)
     else: # Match Frame 0 LAB
         prev_img_lab = cv2.cvtColor(prev_img, cv2.COLOR_RGB2LAB)
         color_match_lab = cv2.cvtColor(color_match_sample, cv2.COLOR_RGB2LAB)
-        matched_lab = match_histograms(prev_img_lab, color_match_lab, multichannel=True)
+        matched_lab = match_histograms(prev_img_lab, color_match_lab, channel_axis=-1)
         return cv2.cvtColor(matched_lab, cv2.COLOR_LAB2RGB)
\ No newline at end of file
deforum commented 1 year ago

thanks ill take a look, a PR would be helpful - i dont have much time