matlab学习

1、matlab图像的裁剪

指定位置裁剪

%% 指定位置裁剪
clc
clear
[I,map]=imread('bird.jpg');
figure;
subplot(121);imshow(I,map);
%指定剪切区域的大小和位置,剪切,返回xy坐标和裁剪区域
[x,y,I2,rect]=imcrop(I,map,[410 540 400 400]);%位置和区域大小
subplot(122);imshow(I2);

手动裁剪

%% 手动裁剪
clc
clear
[I,map]=imread('bird.jpg');
figure;
subplot(121);imshow(I,map);
%指定剪切区域的大小和位置,剪切,返回xy坐标和裁剪区域
[x,y,I2,rect]=imcrop(I,map);
subplot(122);imshow(I2);

2、matlab的自带的图像在哪里

3、一个基于共聚焦三维重建demo

版本1
file_path =‘.’;% 图像文件夹路径(注意misc文件夹后有一个斜杠)
img_path_list = dir(strcat(file_path,‘*.jpg’));%获取该文件夹中所有tiff格式的图像
img_num = length(img_path_list);%获取图像总数量
imgs = cell(1,img_num);
for i=1:img_num
image_name = img_path_list(i).name;% 图像名
imgs{i} =imread(strcat(file_path,image_name));
end

[nrows, ncols] = size(imgs{1});
maxVal_Mat = zeros(nrows,ncols);
maxIdx_Mat = zeros(nrows,ncols);
for nrow = 1:nrows
for ncol = 1:ncols
[maxVal_Mat(nrow, ncol), maxIdx_Mat(nrow, ncol)] = max(cellfun(@(x) x(nrow, ncol) , imgs));
end
end
surf(maxVal_Mat,‘EdgeColor’,‘None’);%绘制z的3D图
% shading interp;
版本2
%读入图像
file_path =‘.’;% 图像文件夹路径(注意misc文件夹后有一个斜杠)
img_path_list = dir(strcat(file_path,‘*.jpg’));%获取该文件夹中所有tiff格式的图像
img_num = length(img_path_list);%获取图像总数量
%定义存放轴向扫描图像的
if img_num>0
for i = 1:img_num %逐一读取图像
for j=1:2048
for k=1:2048
Z_grayThreeValue(i,j,k)=0;
end
end
end
end
%定义存放轴向最大灰度值
if img_num>0
for j=1:2048
for k=1:2048
New_Z_grayThreeValue(j,k)=0;
end
end
end
%
if img_num > 0 %有满足条件的图像
for i = 1:img_num %逐一读取图像
image_name = img_path_list(i).name;% 图像名
image =imread(strcat(file_path,image_name));
for j=1:2048
for k=1:2048
Z_grayThreeValue(i,j,k)=image(j,k);
end
end
end
end
%
Z_grayValue=[1,img_num];
for j=1:2048
for k=1:2048
for i=1:img_num
Z_grayValue(1,i)=Z_grayThreeValue(i,j,k);
end
New_Z_grayThreeValue(j,k)=max(Z_grayValue);
end
end
surf(maxVal_Mat,‘EdgeColor’,‘None’);%绘制z的3D图
shading interp;

4、给师兄写的处理三通道颜色的demo

版本1
clc;
clear all;
[image,map] = imread(‘IMG_20220531_144337.jpg’);
figure
imshow(image);
[x,y,I2,rect]=imcrop(image,map);
imshow(I2);
%R通道
figure;
R = I2(:,:,1);
subplot(1,3,1);
imwrite(R,‘R.jpg’)
imshow®;
title(‘R通道’);
%%G通道
G = I2(:,:,2);
subplot(1,3,2);
imwrite(G,‘G.jpg’)
imshow(G)
title(‘G通道’)
%%B通道
B = I2(:,:,3);
subplot(1,3,3);
imwrite(B,‘B.jpg’)
imshow(B)
title(‘B通道’)
%%矩阵的平均值
R_avg=mean(R(😃)
G_avg=mean(G(😃)
B_avg=mean(B(😃)
版本2
clc;
clear all;
file_path = ‘.’;% 图像文件夹路径
img_path_list = dir(strcat(file_path,‘*.jpg’));%获取该文件夹中所有png格式的图像
img_num = length(img_path_list)%获取图像总数量
R_avg=cell(1,img_num);
G_avg=cell(1,img_num);
B_avg=cell(1,img_num);
if img_num > 0 %有满足条件的图像
for j = 1:img_num %逐一读取图像
image_name = img_path_list(j).name;% 图像名
[image,map] = imread(strcat(file_path,image_name));
image_part=imcrop(image,map,[1900,2750,1950,1950]);%(1900,2750)左上角坐标,(1950,1950)从坐标出发的长宽
% imshow(image_part)
R = image_part(:,:,1);
R_incir=f_Cut_for_circleMask(R,975,975,950,0);
% figure
% imshow(R_incir);
G = image_part(:,:,2);
G_incir=f_Cut_for_circleMask(G,975,975,950,0);
% figure
% imshow(G_incir);
B = image_part(:,:,3);
B_incir=f_Cut_for_circleMask(B,975,975,950,0);
% figure
% imshow(B_incir);
R_sum=sum(R_incir(😃);
R_numincir=sum(sum(R_incir~=0));%在指定圆心和半径的圆内的点的数量
R_avg{j}=R_sum/R_numincir;
%
G_sum=sum(G_incir(😃);
G_numincir=sum(sum(G_incir~=0));
G_avg{j}=G_sum/G_numincir;
%
B_sum=sum(B_incir(😃);
B_numincir=sum(sum(B_incir~=0));
B_avg{j}=B_sum/B_numincir;
end
end

function E_out= f_Cut_for_circleMask(E_in,Center_x,Center_y,Cir_Radiu,A)
% 函数功能:将输入矩阵按照像素值为单位进行圆形区域截取
% E_in:输入矩阵
% Center_x:截取圆形区域的中心坐标x
% Center_y:截取圆形区域的中心坐标x
% Cir_Radiu:截取圆形区域的截取半径像素值
% 注意:这三个参数均是像素值为单位
% A:截取后的其余部分赋值
[xnums,ynums] = size(E_in);
E_out = E_in;
for nx = 1:xnums
for ny = 1:ynums
if abs((nx - Center_x) + 1i*(ny - Center_y)) < Cir_Radiu
E_out(nx, ny) = E_in(nx, ny);
else
E_out(nx, ny) = A;
end
end
end
end

5、matlab自动整理代码格式

Ctrl+All;Ctrl+I

6、读取轴向序列图像,生成灰度值随轴向距离变换的图

7、分段函数的绘制

8、matlab画图,添加图名,坐标轴名,曲线名称(图例)

9、matlab怎么产生一个随机数,matlab怎么产生随机数

10、画9个并列图像

%标准样本数据
x=0:0.01:5;
y=zeros(size(x));
for i=1:length(x)
if x(i)<2.5
y(i)=2;
else
y(i)=1;
end
end
%测量得到的数据
x1=0:0.01:5;
y1=zeros(size(x1));
for i=1:length(x)
if x1(i)<2.5
y1(i)=unifrnd(1.8,2.2);
else
y1(i)=unifrnd(0.8,1.2);
end
end
%绘图
subplot(3,3,1)
plot(x,y,‘r’);hold on;
plot(x1,y1,‘g’)
xlabel(‘横向位移(X)’)
ylabel(‘轴向高度’)
title(‘截面(1)’)
subplot(3,3,2)
plot(x,y,‘r’);hold on;
plot(x1,y1,‘g’)
xlabel(‘横向位移(X)’)
ylabel(‘轴向高度’)
title(‘截面(2)’)
subplot(3,3,3)
plot(x,y,‘r’);hold on;
plot(x1,y1,‘g’)
xlabel(‘横向位移(X)’)
ylabel(‘轴向高度’)
title(‘截面(3)’)
subplot(3,3,4)
plot(x,y,‘r’);hold on;
plot(x1,y1,‘g’)
xlabel(‘横向位移(X)’)
ylabel(‘轴向高度’)
title(‘截面(4)’)
subplot(3,3,5)
plot(x,y,‘r’);hold on;
plot(x1,y1,‘g’)
xlabel(‘横向位移(X)’)
ylabel(‘轴向高度’)
title(‘截面(5)’)
subplot(3,3,6)
plot(x,y,‘r’);hold on;
plot(x1,y1,‘g’)
xlabel(‘横向位移(X)’)
ylabel(‘轴向高度’)
title(‘截面(6)’)
subplot(3,3,7)
plot(x,y,‘r’);hold on;
plot(x1,y1,‘g’)
xlabel(‘横向位移(X)’)
ylabel(‘轴向高度’)
title(‘截面(7)’)
subplot(3,3,8)
plot(x,y,‘r’);hold on;
plot(x1,y1,‘g’)
xlabel(‘横向位移(X)’)
ylabel(‘轴向高度’)
title(‘截面(8)’)
subplot(3,3,9)
plot(x,y,‘r’);hold on;
plot(x1,y1,‘g’)
xlabel(‘横向位移(X)’)
ylabel(‘轴向高度’)
title(‘截面(9)’)
10、matlab中的矩阵同时乘一个数、除以个数
https://zhidao.baidu.com/question/533527781.html

12、matlab中max的用法

13、计算峰值函数的半高宽

14、MATLAB基础讲解与matlab图像处理入门基础

14.1 MATLAB概述

Matlab的应用场景
科研、仿真、金融、算法等
Matlab的安装

程序退出快捷键

Matlab的卸载

控制面板删除

Matlab常用命令

Matlab工具箱&帮助系统

14.2 MATLAB基础

内容介绍
本章将介绍MATLAB的一些基础知识,包括基本的数据类型、运算符和特殊的符号等,以及MATLAB中日期和时间的表示方法、计时函数的应用。本章的知识是MATLAB编程的基础,需要用户多操作,熟练掌握。

数据类型
在MATLAB中有15种基本的数据类型,分别是8种整型数据、单精度浮点型、双精度浮点型、逻辑型、字符串型、单元数组、结构体类型和函数句柄。这15种基本数据类型,如表2.1所示。

数据类型的表示和分类
在MATLAB中,数值类型分为整数和浮点数,整数分为有符号整数和无符号整数,浮点数分为单精度浮点数和双精度浮点数。下面介绍整数、浮点数和复数,以及数值的显示格式等。

取整函数
可以采用不同的方法将小鼠转换为整数

单精度&双精度
在MATLAB中,浮点数包括单精度浮点数(single)
和双精度浮点数( double)。其中双精度浮点数是MATLAB中默认的数据类型。
在MATLAB中,双精度浮点采用8个字节,即64位来表示,其
中第63位表示符号,0为正,1为负,第52-62位表示指数部分,第0-51位表示小数部分。
在MATLAB中,单精度浮点数采用4个字节,即32位来表示,
其中第31位为符号位,0为正,1为负,第23-30位为指数部分,0-22位为小数部分。单精度浮点数比双精度浮点数能够表示的数值范围和数值精度都小。

复数
复数是对实数的扩展,包含实部和虚部两部分,虚部的单位是-1的平方根。在MATLAB中,采用i或j表示虚部的单位。可以采用赋值语句直接产生复数,也可以采用函数complex()来产生复数。

10分钟

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

北岩山人Oo

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值