1. 对序列进行洗牌 randperm()

randperm()产生随机的序列
%if filepaths 是一个5*1的结构体,then cshuffle = randperm(length(filepaths)) %对filepaths进行随机的洗牌,得到了 cshuffle => [2,5,4,1,3] 洗牌后的序列

2. 图像灰度化 rgb2gray()

MyYuanLaiPic = imread('e:/image/matlab/Cluo.jpg');%读取RGB格式的图像
MyFirstGrayPic = rgb2gray(MyYuanLaiPic);%用已有的函数进行RGB到灰度图像的转换 [rows , cols , colors] = size(MyYuanLaiPic);%得到原来图像的矩阵的参数
MidGrayPic = zeros(rows , cols);%用得到的参数创建一个全零的矩阵,这个矩阵用来存储用下面的方法产生的灰度图像
MidGrayPic = uint8(MidGrayPic);%将创建的全零矩阵转化为uint8格式,因为用上面的语句创建之后图像是double型的 for i = :rows
for j = :cols
sum = ;
for k = :colors
sum = sum + MyYuanLaiPic(i , j , k) / ;%进行转化的关键公式,sum每次都因为后面的数字而不能超过255
end
MidGrayPic(i , j) = sum;
end
end
imwrite(MidGrayPic , 'E:/image/matlab/Cluo.png' , 'png'); %显示原来的RGB图像
figure();
imshow(MyYuanLaiPic); %显示经过系统函数运算过的灰度图像
figure();
imshow(MyFirstGrayPic); %显示转化之后的灰度图像
figure();
imshow(MidGrayPic);

3. 对图像进行旋转和翻转

function I = data_augmentation(I, K)

if K ==
return;
elseif K == % flipped
I = flipud(I);
return;
elseif K == % rotation
I = rot90(I,);
return;
elseif K == % rotation & flipped
I = rot90(I,);
I = flipud(I);
return;
elseif K == % rotation
I = rot90(I,);
return;
elseif K == % rotation & flipped
I = rot90(I,);
I = flipud(I);
return;
elseif K == % rotation
I = rot90(I,);
return;
elseif K == % rotation & flipped
I = rot90(I,);
I = flipud(I);
return;
end

4. 对array进行连接 cat(dim, A, B)

5.对图像进缩放,imresize()

HR_current  = imresize(HR,nscales(j,i),'bicubic');
%第二个参数为缩放因子,e.g. 0.5、0.8
%第三个参数为缩放method

6.读取图像默认的数据类型uint8,最大值为255;但是在进行图形矩阵的操作和变化过程中非常容易溢出,所以需要转化为double(64为,0~1)或者single

im2double()将值0~255映射到0~1之间

7.两个循环搞定patch的获取

 for x = +step1 : stride : (hei-patchsize+)
for y = +step2 : stride : (wid-patchsize+)
count = count + ;
subim_label = HR_current(x : x+patchsize-, y : y+patchsize-,:nch);
imdb.HRlabels(:, :, :, count) = subim_label;
if count<=diffPatches %不够一个patch进行填充
imdb.HRlabels(:, :, :, end-count+) = HR_current(x : x+patchsize-, y : y+patchsize-,:nch);
end
end
end

8.产生图像的patch

function [imdb] = generatepatches

%% Note, set your training image set first, large dataset is prefered!
folders = {'path_of_your_training_dataset'}; % set this first! stride = ; % control the number of image patches
patchsize = ; batchSize = ; % important for BNorm
count = ;
nch = ; % for grayscale image, for color image step1 = ;
step2 = ; ext = {'*.jpg','*.png','*.bmp'};
filepaths = []; for j = :length(folders)
for i = : length(ext)
filepaths = cat(,filepaths, dir(fullfile(folders{j}, ext{i}))); %获取folder获取所有figure
end
end cshuffle = randperm(length(filepaths)); % randperm获取filepaths的随机排列
nimages = round(length(filepaths)); % control the number of image patches 去整数 ns = ;
nscales = min(,0.45 + 0.05*randi(,[ns,nimages])); %产生随机矩阵 * all values are less than
naugment = randi(,[,nimages]); %产生一个随机矩阵1* all values are form - for i = : nimages
% HR = imread(fullfile(filepaths(cshuffle(i)).folder,filepaths(cshuffle(i)).name));
HR = imread(fullfile(folders{},filepaths(cshuffle(i)).name)); %从文件夹里随机读取一张图片
HR = HR(:,:,); %如果是rgb图就获取一个通道的,如果是gray图则自然为该图像 HR = data_augmentation(HR, naugment(i)); % 数据增大data_augmentation data_augmentation(HR, ); 转到data_augmentation.m里面就将图片旋转90度
disp([i,nimages,round(count/batchSize)]) for j = : size(nscales,) % size(nscales,) 为1 HR_current = imresize(HR,nscales(j,i),'bicubic'); %对图像进行尺度的缩放
[hei,wid,~] = size(HR_current); % 得到此时的高和宽
for x = +step1 : stride : (hei-patchsize+) % 产生的patch (hei-patchsize+)这个value是一个临界值,最后放不了一个patch
for y = +step2 : stride : (wid-patchsize+)
count=count+;
end
end
end
end numPatches = ceil(count/batchSize)*batchSize; %ceil(1.2)=> ceil(0.2)=> 总共有多少个patch
diffPatches = numPatches - count; % 真实的差了多少个patch
disp([numPatches,numPatches/batchSize,diffPatches]); disp('-----------------------------'); %------------------------------------------------------------------
%------------------------------------------------------------------ count = ;
imdb.HRlabels = zeros(patchsize, patchsize, nch, numPatches,'single'); %imdb是一个结构体 *** for i = : nimages
% HR = imread(fullfile(filepaths(cshuffle(i)).folder,filepaths(cshuffle(i)).name));
HR = imread(fullfile(folders{},filepaths(cshuffle(i)).name)); %从文件夹里随机读取一张图片 if nch == && size(HR,) == %rgb2gray
HR = rgb2gray(HR);
end HR = data_augmentation(HR, naugment(i)); % 图像旋转操作
disp([i,nimages,round(count/)]) for j = : size(nscales,) HR_current = imresize(HR,nscales(j,i),'bicubic'); %图像进行随机的缩放
[hei,wid,~] = size(HR_current);
HR_current = im2single(HR_current); for x = +step1 : stride : (hei-patchsize+)
for y = +step2 : stride : (wid-patchsize+)
count = count + ;
subim_label = HR_current(x : x+patchsize-, y : y+patchsize-,:nch);
imdb.HRlabels(:, :, :, count) = subim_label;
if count<=diffPatches %不够一个patch进行填充
imdb.HRlabels(:, :, :, end-count+) = HR_current(x : x+patchsize-, y : y+patchsize-,:nch);
end
end
end
end
end imdb.set = uint8(ones(,size(imdb.HRlabels,)));

9.求某一个矩阵的指定维度的大小

size(A,dims) = value
# 如xx是一个16*401的矩阵,则求到第一维度的大小16 size(xx,1) =>16 # 如xx是一个16*401的矩阵,则求到第二维度的大小401 size(xx,2) =>401

  

Matlab的用法总结的更多相关文章

  1. matlab fscanf用法

    matlab fscanf用法 matlab中的fscanf的用法如下: A=fscanf(fid,format)[A, count]=fscanf(fid,format,size) [A, coun ...

  2. Matlab norm 用法小记

    Matlab norm 用法小记 matlab norm (a) 用法以及实例 norm(A,p)当A是向量时norm(A,p)   Returns sum(abs(A).^p)^(1/p), for ...

  3. matlab fspecial 用法解释

    Matlab 的fspecial函数用法 fspecial函数用于建立预定义的滤波算子,其语法格式为:h = fspecial(type)h = fspecial(type,para)其中type指定 ...

  4. Matlab基本用法

    转至:http://blog.sina.com.cn/s/blog_8354dda801012dyn.html 目录: 一.说明 二.数据类型及基本输入输出 三.流程控制 四.循环 五.数组.数组运算 ...

  5. matlab ()的用法

    经常见到标识符+(),用法比如阵列Y().函数f()..... 时机到了,会总结一下.

  6. MATLAB入门教程

    MATLAB入门教程   1.MATLAB的基本知识 1-1.基本运算与函数    在MATLAB下进行基本数学运算,只需将运算式直接打入提示号(>>)之後,并按入Enter键即可.例如: ...

  7. (转)MATLAB入门教程

    MATLAB入门教程   1.MATLAB的基本知识 1-1.基本运算与函数    在MATLAB下进行基本数学运算,只需将运算式直接打入提示号(>>)之後,并按入Enter键即可.例如: ...

  8. Matlab各种拟合

    作者:Z-HE链接:https://zhuanlan.zhihu.com/p/36103034来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明出处. 1) polyfit 代码 ...

  9. matlab代码学习_2018-7-28

    1.核范数||A|| * 是指矩阵奇异值的和,英文称呼叫Nuclear Norm.matlab code:[s, u, v] = svd(A); nulear_norm = sum(diag(s)); ...

随机推荐

  1. PowerDesigner 15进行逆向工程生成数据库图表时,注释的comment的生成,解决PowerDesigner逆向工程没有列注释

    使用PowerDesigner默认配置逆向工程是没有注释(name列为英文,comment列是空的),这样的不方便查看字段具体是什么意义,将注释一同导出,方便查看字段具体的意义,如下图 注释列导出步骤 ...

  2. php冒泡排序详解笔记

    冒泡 /* * 冒泡排序(从小到大) * 介绍: * 它重复地走访过要排序的数列,一次比较两个元素,如果他们的顺序错误就把他们交换过来. * 思路: * 比较相邻的元素.如果第一个比第二个大,就交换他 ...

  3. php四个常用类封装

    这4个类分别是Mysql类. 分页类.缩略图类.上传类. Mysql类 <?php /** * Mysql类 */ class Mysql{ private static $link = nul ...

  4. c++ protobuf序列化

    只看了int类型的序列化,后面的有时间再研究 #include <vector> #include <iostream> int main() { ; while (true) ...

  5. java 的访问权限控制

    package test06; public class PermissionModel { private int age; public String name; public int getAg ...

  6. 一次完整的从webshell到域控的探索之路

    前言 内网渗透测试资料基本上都是很多大牛的文章告诉我们思路如何,但是对于我等小菜一直是云里雾里. 于是使用什么样的工具才内网才能畅通无阻,成了大家一直以来的渴求. 今天小菜我本着所有师傅们无私分享的精 ...

  7. spring-boot 集成 log4j 记录日志

    1.pom文件中移除和添加依赖 <!-- 移除boot—starter 的log4j --> <dependency> <groupId>org.springfra ...

  8. String字面量

    public class assa{ static String ee = "aa";//ee指向常量池中的aa static String ff = new String(&qu ...

  9. Ubuntu 18.04安装JDK并配置环境变量

    1.官网下载jdk 下载链接 http://www.oracle.com/technetwork/java/javase/downloads/index.html 可以根据自己的系统进行下载 2.进行 ...

  10. C和C指针小记(十四)-字符串、字符和字节

    1.字符串 C语言没有字符串数据类型,因为字符串以字符串常量的形式出现或存储于字符数组中. 字符串常量和适用于那些程序不会对他们进行修改的字符串. 所有其他字符串都必须存储于字符串数组或动态分配的内存 ...