0% found this document useful (0 votes)
133 views4 pages

Histogram

This document contains MATLAB code for a histogram GUI. It includes functions for opening and closing the GUI, selecting different color channels in a histogram plot, loading an image, and computing and plotting histograms of the color channels. The GUI allows users to load an image, select which color channel(s) to view in the histogram, and close the GUI.

Uploaded by

Rizky Akbar
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
133 views4 pages

Histogram

This document contains MATLAB code for a histogram GUI. It includes functions for opening and closing the GUI, selecting different color channels in a histogram plot, loading an image, and computing and plotting histograms of the color channels. The GUI allows users to load an image, select which color channel(s) to view in the histogram, and close the GUI.

Uploaded by

Rizky Akbar
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 4

function varargout = histogram(varargin) % HISTOGRAM MATLAB code for histogram.

fig % HISTOGRAM, by itself, creates a new HISTOGRAM or raises the existing % singleton*. % % H = HISTOGRAM returns the handle to a new HISTOGRAM or the handle to % the existing singleton*. % % HISTOGRAM('CALLBACK',hObject,eventData,handles,...) calls the local % function named CALLBACK in HISTOGRAM.M with the given input arguments. % % HISTOGRAM('Property','Value',...) creates a new HISTOGRAM or raises the % existing singleton*. Starting from the left, property value pairs are % applied to the GUI before histogram_OpeningFcn gets called. An % unrecognized property name or invalid value makes property application % stop. All inputs are passed to histogram_OpeningFcn via varargin. % % *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one % instance to run (singleton)". % % See also: GUIDE, GUIDATA, GUIHANDLES % Edit the above text to modify the response to help histogram % Last Modified by GUIDE v2.5 02-Dec-2011 12:57:11 % Begin initialization code - DO NOT EDIT gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @histogram_OpeningFcn, ... 'gui_OutputFcn', @histogram_OutputFcn, ... 'gui_LayoutFcn', [] , ... 'gui_Callback', []); if nargin && ischar(varargin{1}) gui_State.gui_Callback = str2func(varargin{1}); end if nargout [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); else gui_mainfcn(gui_State, varargin{:}); end % End initialization code - DO NOT EDIT % --- Executes just before histogram is made visible. function histogram_OpeningFcn(hObject, eventdata, handles, varargin) % This function has no output args, see OutputFcn. % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % varargin command line arguments to histogram (see VARARGIN) % Choose default command line output for histogram handles.output = hObject; % Update handles structure guidata(hObject, handles);

% UIWAIT makes histogram wait for user response (see UIRESUME) % uiwait(handles.figure1); % --- Outputs from this function are returned to the command line. function varargout = histogram_OutputFcn(hObject, eventdata, handles) % varargout cell array for returning output args (see VARARGOUT); % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Get default command line output from handles structure varargout{1} = handles.output; % --- Executes on selection change in RGB. function RGB_Callback(hObject, eventdata, handles) % hObject handle to RGB (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: contents = cellstr(get(hObject,'String')) returns RGB contents as cell array % contents{get(hObject,'Value')} returns selected item from RGB switch get(handles.RGB, 'Value') case 1 [f1] = histograms(handles.y(:,:,1)); absis = 0:1:255; axes(handles.axes2) plot(absis,f1,'r') grid on case 2 [f2] = histograms(handles.y(:,:,2)); absis = 0:1:255; axes(handles.axes2) plot(absis,f2,'g') grid on case 3 [f3] = histograms(handles.y(:,:,3)); absis = 0:1:255; axes(handles.axes2) plot(absis,f3,'b') grid on end; % --- Executes during object creation, after setting all properties. function RGB_CreateFcn(hObject, eventdata, handles) % hObject handle to RGB (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: popupmenu controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgr oundColor')) set(hObject,'BackgroundColor','white'); end

% --- Executes on button press in pushbutton1. function pushbutton1_Callback(hObject, eventdata, % hObject handle to pushbutton1 (see GCBO) % eventdata reserved - to be defined in a future % handles structure with handles and user data [filename, pathname] = uigetfile( ... {'*.bmp;*.jpg;*.tif;*.gif', 'File Lukisan ' *.bmp', 'Gambar Bmp (*.bmp)'; ... '*.jpg', 'Gambar JPEG (*.jpg)'; ... '*.tif', 'Gambar Tif (*.tif)'; ... '*.gif', 'Gambar Gif (*.gif)'; ... '*.*', 'Kabeh File (*.*)'}, ... 'Pick a file'); y = imread(fullfile(pathname,filename)); axes(handles.axes1); imshow(y); handles.y = y; guidata(hObject, handles);

handles) version of MATLAB (see GUIDATA) (*.bmp, *.jpg, *.tif, *.gif)';

% --- 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 size(handles.y,3)==1 [f1] = histograms(handles.y); absis = 0:1:255; axes(handles.axes2) plot(absis,f1,'k') grid on else [f1] = histograms(handles.y(:,:,1)); [f2] = histograms(handles.y(:,:,2)); [f3] = histograms(handles.y(:,:,3)); absis = 0:1:255; axes(handles.axes2) plot(absis,f1,'r',absis,f2,'g',absis,f3,'b') grid on end;

% --- Executes on button press in pushbutton3. function pushbutton3_Callback(hObject, eventdata, handles) % hObject handle to pushbutton3 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) delete(handles.figure1); function [f] = histograms(cit) [m n]=size(cit); citra = double(cit); for i = 1:256, f(i)= 0;end; for j = 1:m, for k = 1:n f(round(citra(j,k))+1)=f(round(citra(j,k))+1)+1; end; end;

% --- Executes on key press with focus on RGB and none of its controls. function RGB_KeyPressFcn(hObject, eventdata, handles) % hObject handle to RGB (see GCBO) % eventdata structure with the following fields (see UICONTROL) % Key: name of the key that was pressed, in lower case % Character: character interpretation of the key(s) that was pressed % Modifier: name(s) of the modifier key(s) (i.e., control, shift) pressed % handles structure with handles and user data (see GUIDATA)

You might also like