Struggling with slider control
Show older comments
Hi. I have been struggling all morning with this and have thrown in the towel. I am plotting histograms of typically 16bit images, and through the use of a slider control, I want to be able to scan the histogram (and draw a red line) and obtain the intensity (x-axis) as well as the counts at that intesnity (y-axis)

The problem comes when I use binning other than 1 bin = 1 intensity level.
for this example, my max pixel value is 22752, and I want to use 1000 bins.
maxval=max(IM(:))
The histogram is obtained with:
nbins=1000;
[counts,x] = imhist(IM,nbins);
%save data globally
setappdata(0,'Counts',counts);
setappdata(0,'X',x);
setappdata(0,'MaxVal',maxval);
grid on;
hold on;
xlim([0,maxval]);
ylim('auto');
bar(x,counts,'b','EdgeColor','b');
Then on the slider callback, I now calculate the binwidth (should be 22752/1000=22.75, and take the ceiling of it), note my nbins is in an editBin field.
binwidth=idivide(uint32(maxval), uint32(str2num(get(handles.editBin,'String'))), 'ceil')
I then setup the slider:
sliderMax=nbins
sliderMin=1;
set(handles.slider1,'Max',sliderMax);
set(handles.slider1,'Min',sliderMin);
sliderStep = [1, 10] / (sliderMax - sliderMin);
set(handles.slider1,'SliderStep',sliderStep);
So when its clicked, return back the value
p=get(hObject,'Value') %Get value from slider
Drawline and update Intensity and Freq edit boxes:
p=round(p) %in case non integer
x(p) %This is the value of the intensity
plot([x(p) x(p)],[0 max(counts)],'r', 'LineWidth',1);
guidata(hObject, handles);
drawnow;
hold off;
maxval
F=counts(p);
set(handles.editFreq,'String',num2str(F))
set(handles.editIntesnity,'String',num2str(p*binwidth,'%.0f'));
But it all seems messed up.
Are there any obvious mistakes please.
Thankyou
Jason
Accepted Answer
More Answers (0)
Categories
Find more on Graphics Object Programming in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!