I have a 128x1500 image that I need to split into pieces (matlab reads it as 1500x128). But regardless of how columns or rows are oriented, it is a rectangle that's wider than it is tall. I need to figure out how to just split it into 10 or so different pieces (all the same height). The image is a .tiff so online programs that do this don't accept it. I'm working in matlab right now, so if there's a way to do it there that'd be great, but any way to do it at all would be very helpful.
Asked
Active
Viewed 1,583 times
0
-
What output do you want? Do you want to inspect the fragments in matlab or save them to tiffs? – Buck Thorn Jul 24 '13 at 21:50
-
saving them to tiffs would be ideal! – singmotor Jul 24 '13 at 21:55
2 Answers
3
input = rand(1500,128,3); %read your .tiff here
N = 8;
h = 128/N;
img = cell(N,1);
for k = 1:N,
img{k} = input(:,(k-1)*h+1:k*h,:);
end
imshow(img{3});
I used N=8 because you specified that you wanted "same height".

Heretron
- 395
- 1
- 6
- 11
3
Slightly different, starting from the directory containing your tif:
N = 150; % width of individual images, final size: N x 128 (x3)
img = imread(tif_file_name);
M = floor(size(img,1)/N);
img=mat2cell(img(1:M*N,:,:),N*ones(M,1),128,3);
for ii=1:length(img)
imwrite(img{ii},['test' num2str(ii) '.tif'],'tif')
end
Set N
once you decide on a desired output size and specify the filename in tif_file_name
.

Buck Thorn
- 5,024
- 2
- 17
- 27
-
Note that a number `size(img,1) - N*M` of trailing columns in your image array are not saved, but this can be readily changed. – Buck Thorn Jul 25 '13 at 11:19