# How to automatically obtain upper-left pixel coordinates of one of the 4x4 blocks I obtained splitting an image?

21 views (last 30 days)
Claudio Eutizi on 23 Jan 2021
Commented: Image Analyst on 23 Jan 2021
Hello.
I managed to split a 224x224 image into 4x4 blocks with mat2cell.
For example: splittedImage is my 4x4 cell matrix with 56 pixel each cell, I need to obtain automatically from a cell of those the upper-left pixel coordinates in the original image.
How can I do it?
Thank you.

Image Analyst on 23 Jan 2021
Try indexing:
[rows, columns] = size(ca)
for col = 1 : columns
for row = 1 : rows
thisCellContents = ca{row, col};
upperLeftPixelValue = thisCellContents(1,1);
% Now do something with upperLeftPixelValue -- process it somehow.
end
end
It looks like you never read the FAQ, so go here for a good description of how cell arrays work and when to use braces, brackets, or parentheses.
##### 2 CommentsShowHide 1 older comment
Image Analyst on 23 Jan 2021
I don't know off the top of my head. mat2cell is tricky so that's why I never use it. I'd recommend just dividing the number of rows and columns by the grid lengths to get the locations, something like
yourMatrix = ones(80, 120); % Whatever.
[rows, columns] = size(yourMatrix) % Get sizes along each dimension.
% Find out where each tile is divided along.
rowDividingLines = round(linspace(1, 0.75 * rows + 1, 4))
colDividingLines = round(linspace(1, 0.75 * columns + 1, 4))
% Get index of upper left pixel for each tile.
[R, C] = meshgrid(rowDividingLines, colDividingLines)

R2020b

### Community Treasure Hunt

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

Start Hunting!

Translated by