이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
Drawing the gradient histogram of a grey image's one
조회 수: 5 (최근 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?

Ameer Hamza
2020년 5월 11일
Teshan, the histogram only has significant peaks at 0 and 255. Which other peaks are you interested in?

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);

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.

참고 항목
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 (한국어)