Tile an Image using pixels

8 views (last 30 days)
Sam Da
Sam Da on 13 Nov 2011
This is an assignment. The prof has provided us code to tile the images in Lush but since I am working in Matlab, I need to use matlab function. I would assume matlab has some function already built in for it.
This is what his function does: Takes an image of 800x600 pixels and cuts into 7500 non-overlapping, 8x8 pixel tiles. The tiles are turned into 64 dimensional vectors (by lining up pixels in raster order; left to right and top to bottom).
I am really not asking a solution for hw. If you don't believe me you can check out this page: http://www.cs.nyu.edu/~yann/2011f-G22-2565-001/index.html
So, what function in matlab can do this for me.
Thanks
  4 Comments
Image Analyst
Image Analyst on 14 Nov 2011
The word tiling threw me - it doesn't sound like tiling like I usually hear it. So you're saying he takes a 8x8 block from a single image, reshapes it into a 1 by 64 row vector and then does this for all 7500 8x8 blocks in the image, concatenating vertically row by row, so that the resulting array is a 7500 row by 64 column matrix? Okay...so what would you use this for?
Walter Roberson
Walter Roberson on 14 Nov 2011
Use? I don't know. But glancing at the course description, I lean towards it being preparation for a NN.

Sign in to comment.

Answers (2)

Walter Roberson
Walter Roberson on 13 Nov 2011
Insufficient information as you do not indicate what order the tiles are to be considered relative to each other, nor what the output format needs to be.
One solution:
t = mat2cell(YourImage, 8*ones(1,100), 8*ones(1,75));
Vectors = cell2mat(cellfun(@(B) reshape(B.',1,64), t.'(:),'Uniform',0));
It might be possible to skip a step or two there.
Key concept here: if you have a block of data that you need to scan by row, then the way to do that is to transpose the block so that the rows become columns, and then to reshape() in to vectors: reshape uses up the data in order of columns [and thus in order of what were originally rows.]

Sam Da
Sam Da on 14 Nov 2011
Image Analyst about 9 hours ago The word tiling threw me - it doesn't sound like tiling like I usually hear it. So you're saying he takes a 8x8 block from a single image, reshapes it into a 1 by 64 row vector and then does this for all 7500 8x8 blocks in the image, concatenating vertically row by row, so that the resulting array is a 7500 row by 64 column matrix? Okay...so what would you use this for? ------------------------------------------------------------------
Yes, that is what he has precisely done.
We are doing K-means study on this as second step.
So, I want to create a matrix like you described above, perform K-means and then recreate the image.
So, I need 2 functions from Matlab: (1) Image to Matrix conversion (2) Recreating the image after K-means

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!