I have an image where I divided image matrix into cell array each of size 4*4 using mat2cell().Tell me how to get the coordinates of each selected cell array

2 次查看(过去 30 天)
I have wriiten the code as follows:
rgbImage = imread('male.jpg');
[rows columns numberOfColorBands] = size(rgbImage);
padimg=padarray(rgbImage,[0 80],'replicate','post');
size(padimg);
[rows1 columns1 numberOfColorBands1] = size(padimg);
blockSizeR = 4; % Rows in block.
blockSizeC = 4;
wholeBlockRows = floor(rows1 / blockSizeR);
blockVectorR = [blockSizeR * ones(1, wholeBlockRows)];
size(blockVectorR);
wholeBlockCols = floor(columns1 / blockSizeC);
blockVectorC = [blockSizeC * ones(1, wholeBlockCols)];
size(blockVectorC);
ca = mat2cell(padimg, blockVectorR, blockVectorC, numberOfColorBands);
%celldisp(ca);
%imshow('padimg')
%ca{40,40}
%ca{1,1}
%[xc,yc,pixval]=impixel(ca{1,1});
here when I use impixel it displays picture to select pixels..instead i need to get all pixel positions of that cell array without selection

回答(1 个)

Walter Roberson
Walter Roberson 2016-2-21
ca{J,K} is image coordinates (J-1)*4+1 : J * 4, (K-1)*4+1 : K * 4
  2 个评论
Walter Roberson
Walter Roberson 2016-2-22
编辑:Walter Roberson 2016-2-22
No, the coordinates are (J-1)*4+1 : J * 4 and (K-1)*4+1 : K * 4, in all combinations. If you need a complete table of them then:
[gridR, gridC] = ndgrid((J-1)*4+1 : J * 4, (K-1)*4+1 : K * 4);
RC = [gridR(:), gridC(:)];
Now RC will be a 16 x 2 matrix of rows and columns.
Note: Rows correspond to Y coordinates, and columns correspond to X coordinates.
If you have an X, Y coordinate system that is not the same as rows and columns, then small adjustments can be made. For example, if Xcoords and Ycoords are the vectors of X coordinates corresponding to each column and Y coordinates corresponding to each row, then
[gridR, gridC] = ndgrid((J-1)*4+1 : J * 4, (K-1)*4+1 : K * 4);
XY = [Xcoords(gridC(:)), Ycords(gridR(:))];
which will be a 16 x 2 matrix of X and Y coordinates.
And not a single pixel intensity involved.

请先登录,再进行评论。

类别

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

标签

尚未输入任何标签。

Community Treasure Hunt

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

Start Hunting!

Translated by