Image sample from list of file paths

  1. Lets say I have a set of images I want to sample with a data tree of XY positions (each images will have its own branch of positions), how do I do this. Currently I can only sample with one image. Is a way to call up the images at the supplied paths?

  2. Kind of a side question: how to I check the contents of a folder in GhPython? There is no option to import os, so there is no os.listdir() function. I usually do this with my python scripts on my Raspberry Pi, so I can understand if its different on my Windows 7 machine where I run Rhino/Grasshopper.

  3. Better yet is there a way to sample images from inside GhPython?

Something like this?

  Private Sub RunScript(ByVal x As Object, ByVal y As Object, ByRef A As Object) 
    Dim l As New list(Of String)
    For Each d As String In System.IO.Directory.GetFiles(x)
      If d.tolower.Contains(".jpg") Or d.tolower.contains(".jpeg") Or d.ToLower.contains(".png") Then
        l.add(d)
      End If
    Next
    A = l
  End Sub 

[quote=“lawrenceyy, post:1, topic:27794”]
Better yet is there a way to sample images from inside GhPython?
[/quote]You should be able to set up your own sampling routines in Python, getting the image using something like img=System.Drawing.Bitmap(filename) and then img.GetPixel to get pixel color. Not sure how to work with that inside a GHPython component tho…

https://msdn.microsoft.com/en-us/library/system.drawing.bitmap(v=vs.110).aspx

–Mitch

Thanks man.System.IO.Directory.GetFiles() was just what I needed.