www.pudn.com > image_search.rar > image_search.m


function varargout = image_search(varargin) 
% IMAGE_SEARCH M-file for image_search.fig 
%      IMAGE_SEARCH, by itself, creates a new IMAGE_SEARCH or raises the existing 
%      singleton*. 
% 
%      H = IMAGE_SEARCH returns the handle to a new IMAGE_SEARCH or the handle to 
%      the existing singleton*. 
% 
%      IMAGE_SEARCH('CALLBACK',hObject,eventData,handles,...) calls the local 
%      function named CALLBACK in IMAGE_SEARCH.M with the given input arguments. 
% 
%      IMAGE_SEARCH('Property','Value',...) creates a new IMAGE_SEARCH or raises the 
%      existing singleton*.  Starting from the left, property value pairs are 
%      applied to the GUI before image_search_OpeningFunction gets called.  An 
%      unrecognized property name or invalid value makes property application 
%      stop.  All inputs are passed to image_search_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 
 
% Copyright 2002-2003 The MathWorks, Inc. 
 
% Edit the above text to modify the response to help image_search 
 
% Last Modified by GUIDE v2.5 13-May-2008 07:35:47 
 
% Begin initialization code - DO NOT EDIT 
gui_Singleton = 1; 
gui_State = struct('gui_Name',       mfilename, ... 
                   'gui_Singleton',  gui_Singleton, ... 
                   'gui_OpeningFcn', @image_search_OpeningFcn, ... 
                   'gui_OutputFcn',  @image_search_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 image_search is made visible. 
function image_search_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 image_search (see VARARGIN) 
 
% Choose default command line output for image_search 
handles.output = hObject; 
 
% Update handles structure 
guidata(hObject, handles); 
 
% UIWAIT makes image_search wait for user response (see UIRESUME) 
% uiwait(handles.figure1); 
 
 
% --- Outputs from this function are returned to the command line. 
function varargout = image_search_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 slider movement. 
function slider1_Callback(hObject, eventdata, handles) 
global IMG 
Val = round(get(hObject,'Value')); 
ValStr = num2str(Val); 
set(handles.txtR,'string',ValStr); 
IMG1=cat(3,str2num(get(handles.txtR,'string'))*IMG, ... 
           str2num(get(handles.txtG,'string'))*IMG, ... 
           str2num(get(handles.txtB,'string'))*IMG); 
axes(handles.axes3); 
cla; 
imshow(IMG1); 
 
 
% --- Executes during object creation, after setting all properties. 
function slider1_CreateFcn(hObject, eventdata, handles) 
 
usewhitebg = 1; 
if usewhitebg 
    set(hObject,'BackgroundColor',[.9 .9 .9]); 
else 
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor')); 
end 
 
% --- Executes on slider movement. 
function slider2_Callback(hObject, eventdata, handles) 
global IMG 
IMG1=uint8(ones(10,5)); 
Val = round(get(hObject,'Value')); 
ValStr = num2str(Val); 
set(handles.txtG,'string',ValStr); 
IMG1=cat(3,str2num(get(handles.txtR,'string'))*IMG, ... 
           str2num(get(handles.txtG,'string'))*IMG, ... 
           str2num(get(handles.txtB,'string'))*IMG); 
axes(handles.axes3); 
cla; 
imshow(IMG1); 
 
 
% --- Executes during object creation, after setting all properties. 
function slider2_CreateFcn(hObject, eventdata, handles) 
 
usewhitebg = 1; 
if usewhitebg 
    set(hObject,'BackgroundColor',[.9 .9 .9]); 
else 
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor')); 
end 
 
 
% --- Executes on slider movement. 
function slider3_Callback(hObject, eventdata, handles) 
 
global IMG 
Val = round(get(hObject,'Value')); 
ValStr = num2str(Val); 
set(handles.txtB,'string',ValStr); 
IMG1=cat(3,str2num(get(handles.txtR,'string'))*IMG, ... 
           str2num(get(handles.txtG,'string'))*IMG, ... 
           str2num(get(handles.txtB,'string'))*IMG); 
axes(handles.axes3); 
cla; 
imshow(IMG1); 
 
 
% --- Executes during object creation, after setting all properties. 
function slider3_CreateFcn(hObject, eventdata, handles) 
 
usewhitebg = 1; 
if usewhitebg 
    set(hObject,'BackgroundColor',[.9 .9 .9]); 
else 
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor')); 
end 
 
 
% --- Executes on button press in pushbutton1. 
function pushbutton1_Callback(hObject, eventdata, handles) 
 
global RGB  
[filename,pathname] = uigetfile({'*.jpg','JPG(*.jpg)';'*.bmp','BMP(*.bmp)';'*.*','ALL(*.*)'},'File Selector'); 
try, 
if ~isequal(filename, 0) 
fullname=fullfile(pathname,filename); 
RGB =imread(fullname); 
axes(handles.axes1); 
cla; 
imshow(RGB); 
end 
catch,  
    msgbox('Warning: Can not read!','Error','warn'); 
end 
 
 
% --- Executes on button press in pushbutton2. 
function pushbutton2_Callback(hObject, eventdata, handles) 
 
global RGB 
if isempty(RGB)  
    msgbox('Warning: Have no picture!','Error','warn'); 
    return; 
end 
axes(handles.axes2); 
imshow(RGB); 
R=uint8(str2num(get(handles.txtR,'string'))); 
G=uint8(str2num(get(handles.txtG,'string'))); 
B=uint8(str2num(get(handles.txtB,'string'))); 
Rt=RGB(:,:,1); 
Gt=RGB(:,:,2); 
Bt=RGB(:,:,3); 
[r,c]=find(Rt==R); 
m=length(r); 
flag=0; 
axes(handles.axes2); 
set(handles.listbox1,'string',''); 
h = waitbar(0,'Please wait...'); 
if m~=0 
   k=1/m; 
else 
    k=1; 
end 
 
P=zeros(1,m); 
j=1; 
for i=1:m 
    if Gt(r(i),c(i))<=G+5 && Gt(r(i),c(i))>=G-5 && Bt(r(i),c(i))<=B+5 &&  Bt(r(i),c(i))>=B-5 
%     if Gt(r(i),c(i))==G && Bt(r(i),c(i))==B           
        set(handles.listbox1,'string',strvcat(get(handles.listbox1,'string'),[num2str(c(i)),',',num2str(r(i))])); 
        flag=1; 
        P(j)=i; 
        j=j+1; 
    else 
        waitbar(i*k); 
    end 
end 
close(h) 
for i=1:m 
    if P(i)~=0 
       text(c(P(i)),r(P(i)),'+','color','r'); 
    end 
end 
 
if flag==0 
    msgbox('Warning: Have not the paxel!','Error','warn'); 
end 
 
% --- Executes on button press in pushbutton3. 
function pushbutton3_Callback(hObject, eventdata, handles) 
clear all; 
close all hidden; 
 
 
% --- Executes during object creation, after setting all properties. 
function listbox1_CreateFcn(hObject, eventdata, handles) 
 
if ispc 
    set(hObject,'BackgroundColor','white'); 
else 
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor')); 
end 
 
 
% --- Executes during object creation, after setting all properties. 
function axes3_CreateFcn(hObject, eventdata, handles) 
global IMG 
IMG=uint8(ones(10,5)); 
 
 
 
% --- Executes on selection change in listbox1. 
function listbox1_Callback(hObject, eventdata, handles) 
 
 
 
 
 
% --- Executes on button press in pushbutton5. 
function pushbutton5_Callback(hObject, eventdata, handles) 
global IMG 
c = uisetcolor(handles.axes3, 'DialogTitle'); 
c1=uint8(c*255); 
set(handles.txtR,'string',num2str(c1(1))); 
set(handles.txtG,'string',num2str(c1(2))); 
set(handles.txtB,'string',num2str(c1(3))); 
 
set(handles.slider1,'value',c1(1)); 
set(handles.slider2,'value',c1(2)); 
set(handles.slider3,'value',c1(3)); 
 
IMG1=cat(3,c1(1)*IMG,c1(2)*IMG,c1(3)*IMG); 
axes(handles.axes3); 
cla; 
imshow(IMG1);