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.
댓글 수: 0
채택된 답변
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
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 Center 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!