Histogram problem. How to solve?
古いコメントを表示
Good evening, I have the following code to generate the histograms and to calculate the values, and appear in the text boxes:

function calc_val_Callback(hObject, eventdata, handles)
global a;
global bmax bmin bmed;
b = rgb2gray(a); %transforma a figura em escala cinza
axes(handles.hist_gray); %ativa eixos
[counts1,binLocations1] = imhist(b); %calcula ordenadas e abcissas do histograma
bmax = max(max(b));
bmin = min(min(b));
bmed = mean(mean(b));
imhist(b); %desenhar histograma
ylim([0 bmax]); %limita ordenadas entre 0 e máximo
set(handles.max,'String',bmax);
set(handles.min,'String',bmin);
set(handles.med,'String',bmed);
global cmax cmin cmed;
c = im2bw(a); %transforma a figura em escala cinza
axes(handles.hist_bw); %ativa eixos
[counts1,binLocations1] = imhist(c); %calcula ordenadas e abcissas do histograma
cmax = max(max(c));
cmin = min(min(c));
cmed = mean(mean(c));
imhist(c); %desenhar histograma
ylim([0 bmax]); %limita ordenadas entre 0 e máximo
set(handles.maxi,'String',cmax);
set(handles.mini,'String',cmin);
set(handles.medi,'String',cmed);
Just get the gray scale histogram and the values of this histogram. But if export the data to excel, appears the data of the two histograms. In annex shows what appears.
5 件のコメント
John D'Errico
2018 年 2 月 25 日
編集済み: Image Analyst
2018 年 2 月 25 日
Image Analyst
2018 年 2 月 25 日
I don't know exactly what the problem is. And you didn't show the code where you are exporting something to Excel, like with xlswrite() or ActiveX commands so how can we debug why two histograms are being sent to Excel???
Catarina Leitão
2018 年 2 月 25 日
編集済み: Image Analyst
2018 年 2 月 25 日
Image Analyst
2018 年 2 月 25 日
It looks like it should work. You will probably have to upload the m file and .fig file, and the image(s) so we can try it ourselves.
Catarina Leitão
2018 年 2 月 25 日
回答 (1 件)
Walter Roberson
2018 年 2 月 26 日
The result of
c = im2bw(a);
is a logical array. min() and max() of those are 0 and 1, and there are no other values, which is why the imhist(c) is so boring. Meanwhile min() and max() applied to a logical array give logical results. You cannot set the string() property of a uicontrol to a logical value.
Easiest way to fix your code:
c = double(im2bw(a));
カテゴリ
ヘルプ センター および File Exchange で Histograms についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!