Size function regarding image
이전 댓글 표시
a=imread('image');
[~,cc]=size(a);
What does the value of cc indicate about the image?
채택된 답변
추가 답변 (2개)
KSSV
2019년 4월 4일
I = imread('peppers.png') ;
[nx,ny,nt] = size(I)
If your image is RGB, in the baove nx,ny,nz gives number of rows, columns and matrices (here 3) respectively. If binary it will be number of rows, columns with nz = 1.
[nx,ny] = size(I)
If your image is RGB, in the baove nx,ny gives number of rows, and number of columns*number of matrices. If binary it will be number of rows, columns.
It is a simple check..you can check on your own.
Another way to describe the scalar output syntax is simply that the last output argument is always the product of the sizes of any dimensions other than those previously requested.
So
[~,cc] = size(A);
returns the product of the sizes of all dimensions other than dim1.
- If A is 10x20x1, cc is 20
- If A is 10x20x3, cc is 60
- If A is 10x20x3x2, cc is 120
In other words, the last output argument does not strictly refer to a single dimension. If you want to ensure that the nth output argument always returns the size of the nth dimension of your array, you need to request and discard an extra output.
[~,cc,~] = size(A);
In this case, cc always returns the size of dim2 of A. This is the same as
cc = size(A,2);
For images, getting the number of rows, columns would be done by:
[rows,cols,~] = size(A); % discard the last output
Omitting the third output would cause the number of columns to be wrong for any RGB input.
If you can't control the dimensionality of your inputs, and you're using size() with scalar outputs, and you want the outputs to always refer to specific dimensions, then you need to discard the last output.
카테고리
도움말 센터 및 File Exchange에서 Images에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!.png)
