How do I find out the dimensions of a bitmap file to use in a VOP SOP?

   2671   6   1
User Avatar
Member
146 posts
Joined: 9月 2011
Offline
I'm sampling pixels from a bitmap to control point attribs - rows contain the values I need, and I scan across the columns to animate the attribs across time. Simple enough.

But I may want to extend the bitmap sideways to lengthen the animation time, so I need to know how many pixels there are to divide my “u” coordinate by the right amount.

Is there a way I can avoid hard-coding – or requiring the user to update parms – my bitmap file's dimensions into my VOP SOP? The SOP's already got the filename as a parameter, which it uses with a Color Map VOP to actually grab the pixels.
User Avatar
Member
900 posts
Joined: 2月 2016
Offline
Hey, I'm pretty sure there is a clean solution for that, but I could come up only with this dirty work around:

1) load the image in a file node inside a Cop2network, by referencing the image path from the color map parameter.
2) read back the resolution from the “size” parameter (grayed out, but still readable)

NOTE:
one thing one needs to be aware of is that the file node inside the cop network has not a live-link with the outside world, so it won't be refreshed (unless you are already inside the cop network).
So we need to force the cooking of the cop network every time we load a new picture into the color map vop.
To do that we can use the python function cook(force=True) .

Have a look at hip file

cheers
Edited by Andr - 2019年6月11日 10:54:46

Attachments:
readresolution.hiplc (126.0 KB)
readresolution.JPG (60.6 KB)

User Avatar
Member
146 posts
Joined: 9月 2011
Offline
Thanks, andr - that's great. May not be tidy but it'll do for now Much appreciated
User Avatar
Member
900 posts
Joined: 2月 2016
Offline
Hey, maybe doing it only in python would be better, no cops required, but you won't be able to read certain formats (like .pic, .rat)
Have a look at the new hip,
cheers

node = hou.pwd()
filepath = node.parm("parmpath").eval()

from PIL import Image
img = Image.open(filepath)
width, height = img.size

node.parm("imageSizex").set(width)
node.parm("imageSizey").set(height)
Edited by Andr - 2019年6月11日 12:33:59

Attachments:
readresolution2.hiplc (147.1 KB)

User Avatar
Member
7794 posts
Joined: 9月 2011
Online
If you are already in vex to load the texture data, you can try teximport to get the resolution or other metadata.

https://www.sidefx.com/docs/houdini/vex/functions/teximport.html [www.sidefx.com]
User Avatar
Member
900 posts
Joined: 2月 2016
Offline
there was indeed a better way to do that
User Avatar
Member
146 posts
Joined: 9月 2011
Offline
Andr
there was indeed a better way to do that

Yeah but now we've learned a variety of alternative approaches that may come in handy one day

And thanks jsmack - that's perfect. The excuse I needed to do move it into a wrangle instead of a VOP (I do get a bit tangled in VOPs after a while, but they can be handy for finding the right function name - that “View VEX code…” thing is a godsend)
  • Quick Links