pmh47 / dirt

DIRT: a fast differentiable renderer for TensorFlow
MIT License
312 stars 63 forks source link

The pixel value of renderd image exceed 255. #74

Closed ffiioonnaa closed 4 years ago

ffiioonnaa commented 4 years ago

Hi, when I render a mask by setting the color value of vertices to be 255. I find the pixel value of the mask is 255.0006, I posted part of the code. Did I do something wrong?



proj = matrices.perspective_projection(near=0.4, far=20., right=0.1,
                                                   aspect=float(244) / float(244))

projection_matrix = tf.tile(tf.expand_dims(proj, 0), [self.batch_size, 1, 1])

vertices_clip = tf.matmul(vertices_camera, projection_matrix)

render = dirt.rasterise_batch(
                vertices=vertices_clip,
                faces=faces,
                vertex_colors=vertex_colors,
                background=tf.zeros([self.batch_size,self.img_size, self.img_size, 1]),
                width=None, height=None, channels=1, name='render2d_stage%d' % i)```
pmh47 commented 4 years ago

Slight imprecision like this is expected behaviour, due to how the GPU internally does rasterisation. So it's always safest to use robust checks (e.g. >254 instead of ==255).