Comments (8)
Hi,
You can create these texture maps by treating the 3D (x,y,z) locations corresponding to each (u,v) coordinate in the texture image as the RGB value. Different permutations will give different color maps. In our case, we compute a 3D location on the unit sphere corresponding to a (u,v) value and use the (x,y,z) as the color value.
Best,
from csm.
Hi @linpeisensh,
We created a texture map (which is the colorful image) and then we use the predicted UV values to pick colors from the texture map and overlay them on the input image. You can have any texture map you would like, here are the color maps I used to create the colorful images. Below is my snippet
'''
Args
img : torch.FloatTensor C X H x W -- this is the image
uv_map: torch.FloatTensor H x W x 2 -- uv predictions
uv_img: torch.FloatTensor C x H x W -- this the texture map
mask: torch.FloatTensor 1 x H x W -- mask for the object
Returns
uv_rendering: torch.FloatTensor C x H x W
'''
def sample_UV_contour(img, uv_map, uv_img, mask, real_img=True):
img = img.unsqueeze(0)
uv_map = uv_map.unsqueeze(0)
uv_img = uv_img.unsqueeze(0)
uv_sample = torch.nn.functional.grid_sample(uv_img, 2*uv_map-1).squeeze(0)
uv_sample = uv_sample*mask + (1-mask)
# alphas = contour_alphas(uv_img.shape[2], uv_img.shape[3], real_img).unsqueeze(0)
alphas = contour_alphas(uv_img.shape[2], uv_img.shape[3], real_img).unsqueeze(0)* 0 + 1
# pdb.set_trace()
alpha_sample = torch.nn.functional.grid_sample(alphas, 2*uv_map-1).squeeze(0)
# alpha_sample = alpha_sample*0.95 + 0.05
alpha_sample = (alpha_sample>0.0).float()*0.7
# alpha_sample = (alpha_sample > 0.9).float()
alpha_sample = alpha_sample*mask
if real_img:
# uv_rendering = (uv_sample*alpha_sample)*1.0 + img.squeeze(0)*(1-alpha_sample)*0.3 * (mask) + img.squeeze(0)*(1-alpha_sample)* (1-mask)*0.3
uv_rendering = (uv_sample*alpha_sample)*1.0 + img.squeeze(0)*(1-alpha_sample)
uv_rendering = (uv_sample*alpha_sample)*1.0 + img.squeeze(0)*(1-alpha_sample)*0.4 * (mask) + img.squeeze(0)*(1-alpha_sample)* (1-mask)
else:
uv_rendering = (uv_sample*alpha_sample) + (img.squeeze(0)*(1-alpha_sample))
return uv_rendering
Hope this helps!
Nilesh
from csm.
Thank you for your reply!
I will try it.
from csm.
Hi @nileshkulkarni,
I want to know what is contour_alphas in this function.
Thanks!
from csm.
And could you tell me whether I should resize uv_img? If yes, how can I do that?
Since the shape of uv_img is 102410243 (HW3) and img is 3256256 (CHW)
from csm.
The contour_alphas are multiplied by 0 so you can just have it as a tensor of size 1 x H x W. Sorry for not including that function as it is not required anymore
Secondly, it is fine if you have the texture image of size 3 x 1024 x 1024 you don't need to resize it as the nn.grid_sample will handle it.
from csm.
OK, I get the ideal result now.
Thank you very much!
from csm.
Hi @nileshkulkarni, how did you create these texture map?
from csm.
Related Issues (20)
- Is this possible run in Google Colab? HOT 4
- the details from UV map to 3d coordinate HOT 3
- Failures while setting up environment from csm.yml HOT 2
- pre-processed mesh template HOT 4
- Access to Images from ImageNet dataset HOT 2
- mapping 2d and 3d to UV HOT 1
- Cannot replicate the Key Point metrics. HOT 3
- Doubut about PCK Metrics in this paper HOT 3
- How can we get this val/epoch_200/pr_10000.mat?
- External directory is missing HOT 2
- Quaternion Azimuth-Elevation predictor HOT 1
- can not download segkps and anno HOT 1
- GCC loss implementation
- Pre-trained weights? HOT 2
- RuntimeError: CuDNN error: CUDNN_STATUS_MAPPING_ERROR HOT 4
- How to prepare the Pascal 3D and ImageNet dataset?
- csm/csm/docs/testing.md error HOT 5
- csm/docs/testing.md IOError HOT 1
- Remove unnecessary null pointer checks HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from csm.