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
댓글 수: 0
답변 (1개)
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
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 Exchange에서 Lighting, Transparency, and Shading에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!