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

1 次查看(过去 30 天)
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
Image Analyst 2021-1-23
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 个评论
Claudio Eutizi
Claudio Eutizi 2021-1-23
Thank you for the answer.
I wrote the question wrong, i'm sorry.
I don't need the first pixel's value, but its coordinates in the entire image.
Image Analyst
Image Analyst 2021-1-23
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)

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

产品


版本

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by