1)首先,坦陵睁你读入的图像是彩色图(三通道的)而非灰度图,因此[M N] = size(..)的这个N值等于第让岁二维长度乘以3(参见下面MATLAB对size函数说明):
SIZE Size of array.
[M1,M2,M3,...,MN] = SIZE(X) for N>1 returns the sizes of the first N
dimensions of the array X. If the number of output arguments N does
not equal NDIMS(X), then for:
N < NDIMS(X), MN contains the product of the sizes of dimensions N
汪山 through NDIMS(X).
2)你是要求矩阵的均值?通过size(I, 1)以及size(y, 2)这求出来并非整体的均值。
改进程序如下:
I = rgb2gray(imread('13042519680705345X.jpg'));
m = mean2(I);
I2 = I, I3 = I;
I2(I2>m) = 0;
I3(I3<=m) = 0;
figure, imshow(I);
figure, imshow(I2);
figure, imshow(I3);