필터 지우기
필터 지우기

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
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 CenterFile Exchange에서 Annotations에 대해 자세히 알아보기

태그

아직 태그를 입력하지 않았습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by