matlab画统计直方图
时间: 2023-08-23 08:13:26 浏览: 93
zhifangtu.rar_zhifangtu _直方图 matlab
在Matlab中,可以使用以下代码来绘制统计直方图:
```matlab
clc
image = imread('D:\2.png');
image_matrix = image(:,:,1);
image_matrix = double(image_matrix);
\[height, width, channels\] = size(image);
% 灰度映射表,灰度范围在0到255之间
gray_map = zeros(1,256);
for i = 1:height
for j = 1:width
T = image_matrix(i,j);
% 灰度统计计数
if(T == 0)
gray_map(T+1) = gray_map(T+1) + 1;
else
gray_map(T) = gray_map(T) + 1;
end
end
end
% 显示
subplot(1,2,1);
imshow(image);
subplot(1,2,2);
bar(0:255, gray_map, 'grouped');
```
这段代码首先读取图像文件,然后将图像转换为灰度图像。接下来,通过循环遍历每个像素,统计每个灰度值出现的次数,最后使用`bar`函数绘制直方图。在绘制直方图之前,可以使用`imshow`函数显示原始图像。\[1\]\[2\]
#### 引用[.reference_title]
- *1* [Matlab论文插图绘制模板第43期—直方图(histogram)](https://blog.csdn.net/qq_26447137/article/details/126348719)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item]
- *2* [Matlab底层算法实现图像直方图统计](https://blog.csdn.net/qq_43376782/article/details/123717911)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item]
[ .reference_list ]
阅读全文