Drawing the gradient histogram of a grey image's one
3 次查看(过去 30 天)
显示 更早的评论
Hi folks,
I'm trying to plot the differential/gradient of a gray image's histogram, to highlight the points of interest more readily.
Searching for a function that does this hasn't yielded anything, but I'm unsure how to go about this in Matlab.
Is there a tutorial or something similar you can point me towards please?
Thanks in advance
采纳的回答
Ameer Hamza
2020-5-9
See imgradient(): https://www.mathworks.com/help/images/ref/imgradient.html. Can you further clarify your question about the histogram.
20 个评论
Teshan Rezel
2020-5-10
编辑:Teshan Rezel
2020-5-10
Hi Ameer, thanks for your response. To clarify, if I have a histogram for a bw image, I'd like to get the differential of the straight line, to give the rate of change per bin. does that make sense?
So similar to how if you differentiate the graph for displacement vs time, you would get the velocity-time graph, I'm looking to do the same thing to a binary histogram because that should highlight the points of interest in an image.
Ameer Hamza
2020-5-10
Ok. I misunderstood the question. If you just want to take the difference between two consecutive values, then see diff(): https://www.mathworks.com/help/releases/R2020a/matlab/ref/diff.html. If you are looking for something similar to time-velocity then use gradient(): https://www.mathworks.com/help/releases/R2020a/matlab/ref/gradient.html.
Teshan Rezel
2020-5-11
Hi Ameer, thanks for this. Do you know how to represent the histogram in such a form that it can be differentiated?
Ameer Hamza
2020-5-11
How are you creating the histogram? Do you want to extract the numeric data? Also see histcount().
Teshan Rezel
2020-5-11
I'm using histogram() to create the histogram. I've tried using histcount() and then gradient(N, edges) but to no avail...I'm trying to differentiate the frequency by the pixel value (from 0-255) but not entirely sure how to do that in Matlab!
Image Analyst
2020-5-11
Exactly what are the "points of interest" in that image? I mean of course you can call imhist(), but then what? What are you really trying to do? Like get the areas or something? The gradient of the histogram won't give you anything interesting I believe. Maybe you meant the "histogram of oriented gradients" (or HOG), which actually IS something. It tells you about the anisotropy/homogeneity of a region.
Teshan Rezel
2020-5-11
Hi Ameer, this is my code:
I = rgb2gray(I);
imshow(I);
histogram(I)
xlim([100, 256])
ylim([0, 30000])
[N, edges] = histcounts(I);
y = gradient(N, edges);
histogram(y)
Teshan Rezel
2020-5-11
Hi Image Analyst, what I'm trying to do is to highlight the peaks in the histogram a bit better. The peaks correspond to different types of objects in the image, and by differentiating the histogram to make the peaks more clear, it is hoped that can shed some light on the original image.
Can this be done with HOG?
Image Analyst
2020-5-11
编辑:Image Analyst
2020-5-11
No, HOG is for texture. Tell me what gray level(s) you think corresponds to a feature in your image. I want to know the gray level, or gray level range, and what it means about the pixels if they have that gray level, or are in that gray level range?
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/292247/image.jpeg)
Ameer Hamza
2020-5-11
Teshan, the histogram only has significant peaks at 0 and 255. Which other peaks are you interested in?![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/292260/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/292260/image.png)
Teshan Rezel
2020-5-11
Hi Ameer, once we remove the 0 peak for the black packground, there appear to be about 3-4 peaks of interest,right after 0, around 170, and around 250...it's highlighting those that I'm looking to do, but also taking the differential to make them more evident
Teshan Rezel
2020-5-11
Hi image Analyst, just based on the histogram, I'd say the areas of interest are around 0-20, ~170-180 and >250.
Ameer Hamza
2020-5-11
What about findpeaks()
I = imread('image.jpeg');
I = rgb2gray(I);
[N, edges] = histcounts(I);
edges = (edges(1:end-1)+edges(2:end))/2; % mid-points of histogram edges
N([1 end]) = 0;
findpeaks(N, edges);
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/292262/image.png)
Teshan Rezel
2020-5-12
Hi Ameer, thanks for this, its really helpful! Is there any way to then differentiate this graph? I believe the peaks of the differential are to be used to predict a different output from the image, so its important that its done!
Ameer Hamza
2020-5-12
You can calculate the gradient vector like this
I = imread('image.jpeg');
I = rgb2gray(I);
[N, edges] = histcounts(I, 50);
edges = (edges(1:end-1)+edges(2:end))/2; % mid-points of histogram edges
N([1 end]) = 0;
grad = gradient(N, edges);
plot(edges, grad);
The point at which gradient change direction is the same as the locations given by findpeaks.
更多回答(1 个)
Image Analyst
2020-5-13
If you want you can use kmeans() to partition the histogram into sections. Personally I don't think it does a very good job but it will find the peak regions.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/292625/image.png)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!发生错误
由于页面发生更改,无法完成操作。请重新加载页面以查看其更新后的状态。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
亚太
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)