Reputation: 11
I wonder if it is possible to visualize an image matrix in dymola? I have a matrix, the coordinates of each matrix element represent the position of that pixel in the image, and the element value represents the grayscale value of that point in the image. For example, a small image with 10*10 in black is a 10*10 zero matrix, and all-white is a 10*10 matrix with 255. Can such a matrix be visualized in Dymola? Whether it's Plot or 3D animation, it's fine.
Upvotes: 1
Views: 40
Reputation: 794
You can do something like that in the annotation section:
model example
parameter Integer matrix[4,3]=[0,0,0; 0,100,50; 100,0,100; 100,100,150] "(x,y,color)";
equation
annotation (Icon(graphics={
Rectangle(
extent={{matrix[1, 1],matrix[1, 2]},{matrix[1, 1] - 100,matrix[1, 2] - 100}},
fillColor={matrix[1, 3],matrix[1, 3],matrix[1, 3]},
fillPattern=FillPattern.Solid,
pattern=LinePattern.None),
Rectangle(
extent={{matrix[2, 1],matrix[2, 2]},{matrix[2, 1] - 100,matrix[2, 2] - 100}},
fillColor={matrix[2, 3],matrix[2, 3],matrix[2, 3]},
fillPattern=FillPattern.Solid,
pattern=LinePattern.None),
Rectangle(
extent={{matrix[3, 1],matrix[3, 2]},{matrix[3, 1] - 100,matrix[3, 2] - 100}},
fillColor={matrix[3, 3],matrix[3, 3],matrix[3, 3]},
fillPattern=FillPattern.Solid,
pattern=LinePattern.None),
Rectangle(
extent={{matrix[4, 1],matrix[4, 2]},{matrix[4, 1] - 100,matrix[4, 2] - 100}},
fillColor={matrix[4, 3],matrix[4, 3],matrix[4, 3]},
fillPattern=FillPattern.Solid,
pattern=LinePattern.None)}));
end example;
I did a 2x2 matrix here, so it might be a bit tedious to do more than that. Since I don't think you can do loops in this part, I would suggest you write a script (Python, Powershell, whatever you're comfortable with) to get the full code with the appropriate amount of pixels. Also, bear in mind that I used a pixel width of 100 here, so it might be good to adapt it to your needs.
Also, the example is in the Icon section, so instance it in a new model to see the result ;)
Upvotes: 0