face3d icon indicating copy to clipboard operation
face3d copied to clipboard

ValueError: Images of type float must be between -1 and 1

Open danindiana opened this issue 6 years ago • 7 comments

When trying to run example 7_generate_uv_map.py I get an error:

$python 7_generate_uv_map.py Traceback (most recent call last): File "7_generate_uv_map.py", line 50, in io.imsave('{}/uv_texture_map.jpg'.format(save_folder), np.squeeze(uv_texture_map)) File "/home/johnh/.local/lib/python3.6/site-packages/skimage/io/_io.py", line 143, in imsave return call_plugin('imsave', fname, arr, plugin=plugin, **plugin_args) File "/home/johnh/.local/lib/python3.6/site-packages/skimage/io/manage_plugins.py", line 214, in call_plugin return func(*args, **kwargs) File "/home/johnh/.local/lib/python3.6/site-packages/skimage/io/_plugins/pil_plugin.py", line 259, in imsave img = ndarray_to_pil(arr, format_str=format_str) File "/home/johnh/.local/lib/python3.6/site-packages/skimage/io/_plugins/pil_plugin.py", line 163, in ndarray_to_pil arr = img_as_ubyte(arr) File "/home/johnh/.local/lib/python3.6/site-packages/skimage/util/dtype.py", line 492, in img_as_ubyte return convert(image, np.uint8, force_copy) File "/home/johnh/.local/lib/python3.6/site-packages/skimage/util/dtype.py", line 261, in convert raise ValueError("Images of type float must be between -1 and 1.") ValueError: Images of type float must be between -1 and 1.

Might be related to this topic: http://scikit-image.org/docs/stable/user_guide/data_types.html

and this thread appears to be dealing with same issue: https://github.com/scikit-image/scikit-image/issues/2756

image

danindiana avatar Feb 08 '19 22:02 danindiana

What scikit-image version do you have? I have 0.14.0 and it is working fine for me.

HectorAnadon avatar Feb 11 '19 11:02 HectorAnadon

I have scikit-image ver. 0.14.0 and it still does not work. The same error.

I also tried to change the range of values of uv_position_map to (0,1) and (-1,-1) or even (0,255).

Output image almost the same in these 3 cases: ibug_image_008_1_0_posmap

FelixFox avatar Feb 18 '19 12:02 FelixFox

Issue resolved! You should change uv_coords = face3d.morphable_model.load.load_uv_coords('./Data/BFM/stn/BFM_UV.mat') to uv_coords = face3d.morphable_model.load.load_uv_coords('./Data/BFM/Out/BFM_UV.mat')

FelixFox avatar Feb 19 '19 13:02 FelixFox

But it is like that https://github.com/YadiraF/face3d/blob/master/examples/7_generate_uv_map.py#L36

HectorAnadon avatar Feb 19 '19 13:02 HectorAnadon

But it is like that https://github.com/YadiraF/face3d/blob/master/examples/7_generate_uv_map.py#L36

As I understood, script in 7_generate_uv_map.py loads 3d model from example1.mat file with its vertices and colors and creates from it a uv-position map. At the same time it creates from it 2d image and uv-texture map.

And script in 8_generate_posmap_300WLP.py uses an example from 300W_LP dataset (more precisely, .mat file from this) to generate uv-position map .

In these both scripts BFM_UV.mat is used in order to generate uv-position map. First, it is processed in process_uv() and then the result is used in mesh.render.render_colors() function. You can see what happens inside by looking here (What happens here I don't understand completely :) ).

So, If I undestand correctly, these both scripts do almost the same thing in context of uv-position map :)

FelixFox avatar Feb 19 '19 16:02 FelixFox

When trying to run example 7_generate_uv_map.py I get an error:

$python 7_generate_uv_map.py Traceback (most recent call last): File "7_generate_uv_map.py", line 50, in io.imsave('{}/uv_texture_map.jpg'.format(save_folder), np.squeeze(uv_texture_map)) File "/home/johnh/.local/lib/python3.6/site-packages/skimage/io/_io.py", line 143, in imsave return call_plugin('imsave', fname, arr, plugin=plugin, **plugin_args) File "/home/johnh/.local/lib/python3.6/site-packages/skimage/io/manage_plugins.py", line 214, in call_plugin return func(*args, **kwargs) File "/home/johnh/.local/lib/python3.6/site-packages/skimage/io/_plugins/pil_plugin.py", line 259, in imsave img = ndarray_to_pil(arr, format_str=format_str) File "/home/johnh/.local/lib/python3.6/site-packages/skimage/io/_plugins/pil_plugin.py", line 163, in ndarray_to_pil arr = img_as_ubyte(arr) File "/home/johnh/.local/lib/python3.6/site-packages/skimage/util/dtype.py", line 492, in img_as_ubyte return convert(image, np.uint8, force_copy) File "/home/johnh/.local/lib/python3.6/site-packages/skimage/util/dtype.py", line 261, in convert raise ValueError("Images of type float must be between -1 and 1.") ValueError: Images of type float must be between -1 and 1.

Might be related to this topic: http://scikit-image.org/docs/stable/user_guide/data_types.html

and this thread appears to be dealing with same issue: scikit-image/scikit-image#2756

image

I have meet the same question, how did you solve it? The method is mentioned don't work for me.

vastyao avatar May 30 '19 08:05 vastyao

Issue resolved! You should change uv_coords = face3d.morphable_model.load.load_uv_coords('./Data/BFM/stn/BFM_UV.mat') to uv_coords = face3d.morphable_model.load.load_uv_coords('./Data/BFM/Out/BFM_UV.mat')

I don't have matlab on my computer and I don't have the access to install either. Could you give me a copy of Out/BFM_UV.mat

douyh avatar Feb 26 '20 08:02 douyh