3
votes

I got a satellite image of size [17935 10968] pixels, I want to cut image equally and process my required algorithm on individual parts (eg: I need to cut above pixel range into 4 equal parts).

How can I split image without loosing intermediate pixels? My requirement is like (1 to 5600 and 5601 to the end pixel).

And anybody got any idea how to split images that are this big in MATLAB?

5
So the problem is something went wrong handling big data or the way of cutting images?Ray
@Ray I got both.. Any Idea.?ravi raja

5 Answers

7
votes

Method 1

If you have the Image Processing Toolbox, this is the preferred and most efficient method. It utilizes the extremely useful blockproc function which is designed exactly for processing large image in blocks. For instance, it takes care of padding when your image does not divide equally into same size blocks and concatenates results from the processing of blocks into one result matrix.

Best you take a look at the official documentation, but here's how it would look like in your case:

vSize = [17935 10968];
imBig = rand([vSize 3]);
nParts = [2 2]; %means divide into 4 parts, 2 horizontal, 2 vertical

blockproc(imBig, ceil(vSize ./ nParts), @yourAlgorithm);


function res = yourAlgorithm(blockStruct)
   %do your processing of the block here and 
   %optionally return a result in 'res'

   %for example, just return the RGB vector of the first pixel
   res = blockStruct.data(1,1,:);
end

Method 2

If you don't have the Image Processing Toolbox you can use the mat2cell function instead. Fisrt you figure out the required block sizes and then you get a cell array containing the different blocks. For such large images though, speed and memory may become an issue. The code is borrowed from this Matlab Central answer.

vSize = [17935 10968];
imBig = rand([vSize 3]);
nParts = [2 2]; %means divide into 4 parts, 2 horizontal, 2 vertical

%figure out the size of "regular" block and the last block

vRegBlockSize = ceil(vSize ./ nParts);
vLastBlockSize = vSize - vRegBlockSize .* (nParts - 1);

%put the sizes into a vector
vSplitR = [vRegBlockSize(1)*ones(1,nParts(1)-1), vLastBlockSize(1)];
vSplitC = [vRegBlockSize(2)*ones(1,nParts(2)-1), vLastBlockSize(2)];

%split the image
C = mat2cell(imBig, vSplitR, vSplitC, 3);

%access RGB pixel (x,y) in top left {1,1} block
p = C{1,1}(x, y, :);
2
votes
upperLeft = theImage(1:5600, 1:5600, :);
upperRight = theImage(1:5600, 5601:end, :);
lowerLeft = theImage(5601:end, 1:5600, :);
lowerLeft = theImage(5601:end, 1:5601:end, :);
1
votes

you can use reshape to make 4 matrices from the image:

A=reshape(Img, 17935 , 10968/4,[]);

then process A(:,:,1) , etc...

1
votes

Use the following code to divide the image into 4 different images:

A=reshape(Img, 17935 , 10968/4, 3, []);

then A(:,:,:,1) is the first image.

0
votes

Suppose A is your 17935x10968x3 matrix, I think you can do:

B = reshape(A, 17935, 10968 / 4, 4, 3);

In this way the last dimension still represents RGB. Only difference is that it becomes 4-D array.