Property settings for axes of greyscale histogram on gui?

Im trying to plot a histogram of a grey scale image using a gui, I'm having trouble with the property inspector belonging to the axes which Im using in the gui.fig? how do I get the axes to be 0-256 along the x axis (greyscale) etc?

Risposte (1)

After you call bar() or plot(), just use xlim().
xlim([0, 255]);
By the way, gray levels don't go past 255 unless you have a 16 bit image or a floating point image. You can't get 256 with a uint8 image.

9 Commenti

hi, Ive inserted that line of code under the function for the
histogram push button in my gui.m file. However the plot is still odd looking, is there something I'm not doing in the property inspector in order to create the histogram of a grey scale image? attached is the plot.....
it should look like this ....
This is what I get when i enter code into the command line...
You forgot to attach gui.m. If it's a script, then it should be the same as when you type each line into the command window one line at a time.
Here is the code from my * gui.m * file for my histogram push button:
% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA
if isfield(handles,'MyImage')
axes(handles.axes2);
A=hist(double(handles.MyImage(:)),255);
colormap(gray(256));
colorbar off;
xlim([0, 255]);
ylim([0, 3000]);
plot(A)
end
Here is the code from the * gui.m * fie which allows you to browse your directory for an image, this is where the 'MyImage' or 'handles.MyImage' comes from:
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%%Initial Method
[filename pathname] = uigetfile({'*.bmp';'*.jpg'},'File Selector');
handles.MyImage = strcat(pathname, filename);
%handles.MyImage=MyImage(:,:,1);
axes(handles.axes1);
imshow(handles.MyImage)
set(handles.edit1,'string',filename);
set(handles.edit2,'string',handles.MyImage);
%save the updated handles object
guidata(hObject,handles);
NOTE: that Ive slightly manipulated the code from the initial histogram I've showed you. using 255 bins instead off 100. also the plot below uses the 'hist' function and not 'histogram'. although the histogram below is slightly better, it is still nothing compared to what it should be...
You still forgot to attach the files. If you want me to try anything, attach the m and fig files and the image file.
Here is the .m file
Here is the image
I tried compressing the .fig file to a zip but it is still 15.1MB which is too large to attach!

Accedi per commentare.

Richiesto:

il 2 Mar 2015

Commentato:

il 4 Mar 2015

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by