Reputation: 4180
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.
Upvotes: 0
Views: 1606
Reputation: 5073
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
.
Upvotes: 3
Reputation: 425
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".
Upvotes: 3