提取图片亮度信息,对比较亮的区域进行高亮显示
原图
结果图:
算法伪代码如下:
1. 从文件中读取图像('img.jpg')并存储在变量image中。
2. 将图像转换为灰度图像,存储在变量gray_image中,使用Matlab内置函数rgb2gray()。
3. 计算灰度图像的平均亮度值,存储在变量brightness中,使用Matlab内置函数mean()。
4. 显示亮度值,使用Matlab内置函数disp()。
5. 创建一个自定义的颜色映射custom_map,使用Matlab内置函数colormap()和jet()来生成256个颜色的映射。
6. 将灰度图像转换为索引图像,将其映射到256个颜色,存储在变量indexed_image中,使用Matlab内置函数gray2ind()和ind2rgb()。
7. 显示索引图像,使用Matlab内置函数imshow(),并设置颜色映射为custom_map,使用Matlab内置函数colormap(),最后显示颜色栏,使用Matlab内置函数colorbar()。
close all;
clc;
clear;
% 读取图片
image = imread('img.jpg');
% 将图片转换为灰度图像
gray_image = rgb2gray(image);
% 计算图像的亮度值
brightness = mean(gray_image(:));
disp('亮度值为:')
disp(brightness)
% 创建自定义的颜色映射
custom_map = colormap(jet(256));
% 根据亮度值映射颜色
indexed_image = ind2rgb(gray2ind(gray_image, 256), custom_map);
% 显示图像
figure;
imshow(indexed_image);
colormap(custom_map); % 设置颜色映射
colorbar;