How to create an image with a matrix and a cell array
Ältere Kommentare anzeigen
I'm currently trying to create an Image of a 2D Game Map in Matlab.
Using a 3rd party program i have created a Matrix M, that designates where which tile should be used.
As of now my Code looks like this:
I=imread('tileset1.png');
M=dlmread('Karte.txt');
%Creating the tiles using the picture
Tileset.width.tiles=32; %Width of my tileset1.png in tiles
Tileset.height.tiles=19; %height of my tileset in tiles
Tile.width=12; %width of a tile in pixels
Tile.height=12; %height of a tile in pixels
Nr.tiles=Tileset.width.tiles*Tileset.height.tiles;
tile=zeros(0,(Nr.tiles));
for n=1:(Nr.tiles)
x=mod(n,Tileset.width.tiles);
y=floor(n/Tileset.width.tiles);
rect=[((x*Tile.width)-Tile.width),((y*Tile.height)+1),Tile.width,(Tile.height-1)];
tile{n}=imcrop(I,rect);
end
I want to create an image using my tile cells in their designated spots using the matrix M.
Thanks in advance !
Edit : I have included Karte.txt and tileset1.png which I use in my code.
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Image Processing Toolbox finden Sie in Hilfe-Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!