毕业设计——人脸检测——002 MATLAB实现提取一张图片像素点的RGB值

来源:互联网 发布:日本女生保养知乎 编辑:程序博客网 时间:2024/05/17 09:33

向Matlab中输入一张jpg图片,提取图片RGB值分别放到三个二维数组里,然后计算红绿蓝均值,完整程序.

clear all,clc;im=imread('1.jpg');%1.jpg为图片,在m文件所在目录下     im矩阵中(x,y,1~3)分别代表红、绿、蓝三色的矩阵s=size(im);R=im(:,:,1);G=im(:,:,2);B=im(:,:,3);R=reshape(R,[s(1),s(2)]);G=reshape(G,[s(1),s(2)]);B=reshape(B,[s(1),s(2)]);r=mean(mean(R));%红色均值g=mean(mean(G));%绿色均值b=mean(mean(B));%蓝色均值
代码来自百度 @天上的一条龙 



cell 单元格 -Create cell array 创建单元格数组

Syntax 语法

C = cell(dim)
C = cell(dim1,...,dimN)
D = cell(obj)

Description 描述

C = cell(dim) creates a cell array of empty matrices. If dim is a scalar, C is dim-by-dim. If dim is a vector, C is dim(1)-by-...-dim(N), where Nis the number of elements of dim.创建一个空矩阵的单元格数组。如果dim是标量,C为dim*dim。如果dim是矢量,C为dim(1)*...*dim(N),N是dim中成员个数

C = cell(dim1,...,dimN) creates cell array C, where C is dim1-by-...-dimN.创建一个数组C,C为dim1*...*dimN

D = cell(obj) converts a Java array or .NET array of System.String or System.Object into a MATLAB cell array. 包含Java数组或.Net中System.String的数组或者System.Object在MATLAB中的单元格数组

Tips 小贴士

Creating an empty array with the cell function, such as使用‘cell’函数创建一个空数组,例如

C = cell(3,4,2);

is exactly equivalent to assigning an empty array to the last index of a new cell array:与分配一个空数组给一个新单元格数组中最后一个索引恰好相同

C{3,4,2} = [];

Input Arguments 输入参数

dim

Scalar integer or vector of integers that specifies the dimensions of cell array C. 整数标量或整数矢量指定单元格数组的维数

dim1,...,dimN

Scalar integers that specify the dimensions of C.  标量整数指定C的维数

obj

One of the following: 一下一种

  • Java array or object JAVA的数组或object类型

  • .NET array of type System.String or System.ObjectSystem.StringSystem.Object型的.Net数组

Output Arguments 输出参数

C

Cell array. Each cell contains an empty, 0-by-0 array of type double. 单元格数组。每个单元格包含一个空的0*0类型为double的数组

D

Cell array. Each cell contains a MATLAB type closest to the Java or .NET type. For more information, see:

单元格数组。每个单元格包含一个MATLAB型类似于JAVA或.NET类型。如果需要更多相关信息,请浏览如下

  • Conversion of Java Return Types

  • .NET Type to MATLAB Type Mapping

Examples 例子

Create an empty 3-by-4-by-2 cell array. 创建一个空的3*4*2的空单元格数组

mycell = cell(3,4,2);
 

Create a cell array that is the same size as mycell, created in the previous example. 创建一个和mycell相同大小的单元格数组

similar = cell(size(mycell));
以上Cell摘自:http://www.mathworks.se/help/techdoc/ref/cell.html 

原创粉丝点击