How to initialize an array of structs in MATLAB?

Using repmat is by far the most efficient way to preallocate structs : N = 10000; b = repmat(struct(‘x’,1), N, 1 ); This is ~10x faster using Matlab 2011a than preallocating via indexing, as in N = 10000; b(N).x = 1 The indexing method is only marginally faster than not preallocating. No preallocation: 0.075524 Preallocate … Read more

Mapping image into cylinder or sphere shape?

The technique is called texture mapping. This is a code example from surface function (R2011b): load clown surface(peaks,flipud(X),… ‘FaceColor’,’texturemap’,… ‘EdgeColor’,’none’,… ‘CDataMapping’,’direct’) colormap(map) view(-35,45) This example loads RGB image from “peppers.png” and maps it onto cylinder: imgRGB = imread(‘peppers.png’); [imgInd,map] = rgb2ind(imgRGB,256); [imgIndRows,imgIndCols] = size(imgInd); [X,Y,Z] = cylinder(imgIndRows,imgIndCols); surface(X,Y,Z,flipud(imgInd),… ‘FaceColor’,’texturemap’,… ‘EdgeColor’,’none’,… ‘CDataMapping’,’direct’) colormap(map) view(-35,45) Things are … Read more

Matlab: How to bend line in image

Ok, here is a way involving several randomization steps needed to get a “natural” non symmetrical appearance. I am posting the actual code in Mathematica, just in case someone cares translating it to Matlab. (* A preparatory step: get your image and clean it*) i = Import@”http://i.stack.imgur.com/YENhB.png”; i1 = Image@Replace[ImageData[i], {0., 0., 0.} -> {1, … Read more