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

1 回表示 (過去 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 件のコメント
alapati pujitha
alapati pujitha 2016 年 2 月 22 日
logic you have given prints the pixel intensities.I require x and y coordinates of each selected cell array
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 Center および File ExchangeLighting, Transparency, and Shading についてさらに検索

タグ

タグが未入力です。

Community Treasure Hunt

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

Start Hunting!

Translated by