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