kritiksoman / GIMP-ML

AI for GNU Image Manipulation Program
https://kritiksoman.github.io/GIMP-ML-Docs/index.html
MIT License
1.39k stars 127 forks source link

Wrong bitmap pass to the AI algorithms #23

Closed datalot-369 closed 3 years ago

datalot-369 commented 3 years ago

Description

Even if the selected layer has no alpha channel, the plugin will give no output if there are alpha pixels in the image.

Steps to reproduce

  1. Open any image with GIMP.
  2. Remove the alpha channel of the layer if it has one.
  3. Scale down the layer 2x. (1024x1024 will be 512x512) 3.1. You will notice an alpha space around the layer.
  4. With the scaled layer selected, apply it a GIML plugin. 4.1. MonoDepth is a quick test.

What happened?

What should happen?

There should be a new layer output of the plugin with the desired effects.

Workaround

  1. Select the layer.
  2. File > Create > From Clipboard
  3. Apply the plugin.

Versioning

 - OS Version: MX Linux 19.2 amd64
 - GIMP Version: 2.10.20
kritiksoman commented 3 years ago

check now

datalot-369 commented 3 years ago

Resume: Not fixed.

KMeans

Traceback (most recent call last):
  File "/usr/lib/gimp/2.0/python/gimpfu.py", line 740, in response
    dialog.res = run_script(params)
  File "/usr/lib/gimp/2.0/python/gimpfu.py", line 361, in run_script
    return apply(function, params)
  File "/home/jeanfar/git-clones/GIMP-ML/gimp-plugins/monodepth.py", line 54, in MonoDepth
    createResultLayer(img, 'new_output', cpy)
  File "/home/jeanfar/git-clones/GIMP-ML/gimp-plugins/monodepth.py", line 40, in createResultLayer
    region[:, :] = rlBytes
TypeError: string is wrong length

MonoDepth

Traceback (most recent call last):
  File "/usr/lib/gimp/2.0/python/gimpfu.py", line 740, in response
    dialog.res = run_script(params)
  File "/usr/lib/gimp/2.0/python/gimpfu.py", line 361, in run_script
    return apply(function, params)
  File "/home/jeanfar/git-clones/GIMP-ML/gimp-plugins/monodepth.py", line 54, in MonoDepth
    createResultLayer(img, 'new_output', cpy)
  File "/home/jeanfar/git-clones/GIMP-ML/gimp-plugins/monodepth.py", line 40, in createResultLayer
    region[:, :] = rlBytes
TypeError: string is wrong length

Deblur

Traceback (most recent call last):
  File "/usr/lib/gimp/2.0/python/gimpfu.py", line 740, in response
    dialog.res = run_script(params)
  File "/usr/lib/gimp/2.0/python/gimpfu.py", line 361, in run_script
    return apply(function, params)
  File "/home/jeanfar/git-clones/GIMP-ML/gimp-plugins/deblur.py", line 44, in deblur
    createResultLayer(img,'deblur_'+layer.name,pred)
  File "/home/jeanfar/git-clones/GIMP-ML/gimp-plugins/deblur.py", line 25, in createResultLayer
    region[:,:]=rlBytes
TypeError: string is wrong length

All works as expected.

kritiksoman commented 3 years ago

@datalot-369 a warning message has been added in the plugin.

datalot-369 commented 3 years ago

Unexpected fix, but it works.

image

Thank you Krity!

valgur commented 3 years ago

@kritiksoman There's no need for that error message, though. You can just pass layer.width and layer.height to createResultLayer() and use them instead of image.width and image.height here https://github.com/kritiksoman/GIMP-ML/blob/master/gimp-plugins/monodepth.py#L38

Also, have you considered moving the common GIMP<->PyTorch translation functionality into a shared Python module, so it's easier to fix bugs like this? Something like https://github.com/valgur/GIMP-ML-Hub/blob/master/plugins/_plugin_base.py. Feel free to ignore the XMLRPC functionality as that's only relevant if you want to run models in a separate Python 3 process. Using such a module from a plugin script only requires the addition of

import sys
from os.path import dirname, realpath
sys.path.append(realpath(dirname(__file__)))

for the local import to work reliably in GIMP.