彩色图像处理(matlab)
一、编程实现RGB彩色空间分割算法
clc,clear
rgb=imread('花朵.jpg');
rgb1=im2double(rgb);
r=rgb1(:,:,1);
g=rgb1(:,:,2);
b=rgb1(:,:,3);
%在红色分量中选择一块矩形区域
r1=r(200:310,400:500);
%矩形区域的均值
r1_u=mean(mean(r1(:)));
[m,n]=size(r1);
%计算标准差
sd1=0.0;
for i=1:m
for j = 1:n
sd1=sd1+(r1(i,j)-r1_u)*(r1(i,j)-r1_u);
end
end
r1_d=sqrt(sd1/(m*n));
r2=zeros(size(rgb1,1),size(rgb1,2));
%找到符合条件的点
ind=(r>r1_u-1.25*r1_d)&(r<r1_u+1.25*r1_d);
%符合条件的点灰度设为1
r2(ind)=1;
rgb2=rgb1;
[m2,n2]=size(r2);
for i =1:m2
for j =1:n2
if r2(i,j)==0
rgb2(i,j,:)=0;
end
end
end
figure
subplot(2,3,1),imshow(rgb1),title('RGB原始图像')
subplot(2,3,2),imshow(r),title('R分量')
subplot(2,3,3),imshow(g),title('G分量')
subplot(2,3,4),imshow(b),title('B分量')
subplot(2,3,5),imshow(r2),title('红色分割')
subplot(2,3,6),imshow(rgb2),title('根据红色分割')
二、编程实现从RGB图像转换为灰度图像的函数
rgb1=imread('花朵.jpg');
[rows , cols , colors] = size(rgb1);
Gray = zeros(rows , cols);
Gray = uint8(Gray);
for i = 1:rows
for j = 1:cols
sum = 0;
for k = 1:colors
sum = sum + rgb1(i , j , k) / 3;
end
Gray(i , j) = sum;
end
end
figure;
subplot(131);
imshow(rgb1);
subplot(132);
imshow(rgb2gray(rgb1));title('系统自带函数')
subplot(133);
imshow(Gray);title('自写函数')
三、RGB转HSI
%hsi2rgb
function hsi = rgb2hsi(rgb)
%实现从RGB到HSI的转换
%输入:rgb向量矩阵
%输出:hsi向量矩阵
rgb = im2double(rgb);
r = rgb(:, :, 1);
g = rgb(:, :, 2);
b = rgb(:, :, 3);
% Implement the conversion equations.
num = 0.5*((r - g) + (r - b));
den = sqrt((r - g).^2 + (r - b).*(g - b));
theta = acos(num./(den + eps));
H = theta;
H(b > g) = 2*pi - H(b > g);
H = H/(2*pi);
num = min(min(r, g), b);
den = r + g + b;
den(den == 0) = eps;
S = 1 - 3.* num./den;
H(S == 0) = 0;
I = (r + g + b)/3;
% Combine all three results into an hsi image.
hsi = cat(3, H, S, I);
相关知识
基于色彩空间的油菜花图像分割
【优化覆盖】基于matlab入侵杂草和花授粉混合算法无线传感器覆盖优化问题【含Matlab源码 1328期】
基于Matlab植物虫害检测(GUI,注释svm算法)
基于颜色特征的农作物病虫害检测(MATLAB程序+word报告)
基于图像处理的花卉识别技术的研究与实现
程序员面试、算法研究、机器学习、大模型/ChatGPT/AIGC、论文审稿、具身智能、RAG等11大系列集锦
使用图像处理技术和卷积神经网络(CNN)的作物病害检测
七夕节—玫瑰花绘制(Matlab)
基于物联网技术的设施蔬菜病害预警与诊断研究
MATLAB
网址: 彩色图像处理(matlab) https://www.huajiangbk.com/newsview174173.html
上一篇: 机器学习入门——鸢尾花问题 |
下一篇: 春节买花怎么选?有心栽花花不活, |
推荐分享

- 1君子兰什么品种最名贵 十大名 4012
- 2世界上最名贵的10种兰花图片 3364
- 3花圈挽联怎么写? 3286
- 4迷信说家里不能放假花 家里摆 1878
- 5香山红叶什么时候红 1493
- 6花的意思,花的解释,花的拼音 1210
- 7教师节送什么花最合适 1167
- 8勿忘我花图片 1103
- 9橄榄枝的象征意义 1093
- 10洛阳的市花 1039