Implement a function with Matlab to output the histogram values of a given grey level image. Display in the boxes the resulting histograms.
时间: 2024-03-03 10:50:31 浏览: 96
运用matlab进行图像处理
Sure, here's an implementation of a function in Matlab that takes a grey level image as input and outputs its histogram:
```matlab
function [hist, edges] = grey_histogram(img)
% img: grey level image
% hist: histogram values
% edges: edges of histogram bins
% Compute histogram
[hist, edges] = histcounts(img, 256);
% Display histogram
figure;
bar(edges(1:end-1), hist);
xlabel('Grey Level');
ylabel('Frequency');
title('Grey Level Histogram');
end
```
To use this function, simply call it with your grey level image as input. For example:
```matlab
img = imread('my_grey_image.jpg');
[hist, edges] = grey_histogram(img);
```
This will display a histogram of the grey levels in your image.
阅读全文