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

1 visualización (últimos 30 días)
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.

Respuesta aceptada

Image Analyst
Image Analyst el 23 de En. de 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 comentarios
Claudio Eutizi
Claudio Eutizi el 23 de En. de 2021
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 el 23 de En. de 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)

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Matrix Indexing en Help Center y File Exchange.

Productos


Versión

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by