Grasshopper

algorithmic modeling for Rhino

Convert an image into a colored mesh and associate each face a text number by color

I have a problem, I would like to transform an image (color or monochrome) in a mesh (with UV value are adjustable to the size of the image) and associate with each color a letter or number (example: black (or RGB value) = A1, green = BB etc ...) and get to the end of a text file with Num. columns = Vmesh and Num. rows = Umesh.

1) there is a problem at the color transition (personally it's possible to even approximate the boundary color (like pixelate effect) to one of two adjacent colors.

2) text file.

I do not know if I was clear but one example for instance could be the one of the images converted to ASCII codes.

Thank you in advance!

Views: 1326

Attachments:

Replies to This Discussion

Maybe this can be a start...

""""""""""""""""""""""""""""

private void RunScript(string path, List<Color> colors, List<string> texts, ref object A)
{
List<string> text = new List<string>();
Bitmap myBitmap = new Bitmap(path);
//A = colors[0];
for (int x = 0; x < (myBitmap.Height); x++) {
for (int y = 0; y < (myBitmap.Width); y++) {
for (int c = 0; c < (colors.Count); c++) {
if (colors[c] == myBitmap.GetPixel(x, y)) {
text.Add(texts[c]);
}
}
}
}
A = text;
}

""""""""""""""""""""""""""""

(use right-click in inputs to change name, Access method and type hint)

Place attached "test.bmp" to a "C:\test\" folder

I think the pattern is vertically flipped because bitmaps are managed with Y at the opposite of normal Cartesian CAD (what? :D I don't know...)

I haven't found how to output to a file...

Attachments:

Thank you so much for your reply, I'll study it as soon as possible.

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