Grasshopper

algorithmic modeling for Rhino

Hey, a while back I modified the GetPixel VB.NET component to also grab color information. I was getting good results but now I'm getting totally inaccurate color information. A lot of repeated colors in vertical bands (but not perfect bands), and not accurate to the JPG at all. Can you take a look at the script and see what the problem might be?

Thanks.

Marc

'-----

Sub RunScript(ByVal arrPts As List(Of On3dPoint), ByVal u As Integer, ByVal v As Integer, ByVal strFileName As String)

Dim arrPt(0 To u, 0 To v) As On3dPoint
Dim bm As New Bitmap(strFileName)
Dim lum_list As New List(Of Double)
Dim hue_list As New List(Of Color)

Dim counter As Integer = 0

v = v + 1

'create a multidimensional array from single list
For i As Int32 = 1 To u - 1
For j As Int32 = 1 To v - 1
arrPt(i, j) = arrPts(counter)
counter = counter + 1
Next
Next

' loop to read the pixels
For i As Int32 = 1 To u
For j As Int32 = 1 To v

Dim pix_x As Int32 = Convert.ToInt32(i * (bm.width - 1) / u)
Dim pix_y As Int32 = Convert.ToInt32(j * (bm.height - 1) / v)
Dim col As Color = bm.getPixel(pix_x, pix_y)

hue_list.Add(col)
lum_list.Add(col.GetBrightness())
Next


Next

'output
A = hue_list
arrLum = lum_list


End Sub

Views: 1473

Replies to This Discussion

Hey Marc,
Haven't tested it recently as I rewrote the getPixel some time ago.
For a few pixels it was working fine, but if you read a bigger image it takes quite long.
I found a solution in locking bits of the Picture into memory.
David probably used that method for the filters in the RhPicture plugin for Rhinoscript.

Don't know if I did everything correct but it works fine for me and is exremely fast.

I've attached it here- maybe you can try if that is a solution for you...

Bye,
Marc
Attachments:

Hoi Marc,

Wouldn't it also be grand if we now could look at a UV point of a surface and request the texture mapping coordinates ?

 

I haven't looked at the rhino sdk yet, but I've done this with blender in the past and it is a really intuitive way of mapping interventions on a surface.

 

gr

sander

 

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service