Построение графического интерфейса в системе Matlab

Автор работы: Пользователь скрыл имя, 21 Ноября 2012 в 21:44, реферат

Краткое описание

Matlab – это система инженерных и научных вычислений. Она обеспечивает математические вычисления, визуализацию научной графики программирование и моделирование процессов с использованием интуитивно понятной среды окружения, когда задачи и их решения могут быть представлены в нотации, близкой к математической.

Содержимое работы - 1 файл

самост ЦОИ.doc

— 475.00 Кб (Скачать файл)

% 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 button press in LoadButton.

function LoadButton_Callback(hObject, eventdata, handles)

% hObject    handle to LoadButton (see GCBO)

% eventdata  reserved - to be defined in a future version of MATLAB

% handles    structure with handles and user data (see GUIDATA)

 

[FileName,PathName] = uigetfile({'*.*'},'Load Image File');

 

if (FileName==0) % cancel pressed

    return;

end

 

 

handles.fullPath = [PathName FileName];

[a, b, Ext] = fileparts(FileName);

availableExt = {'.bmp','.jpg','.jpeg','.tiff','.png','.gif'};

FOUND = 0;

for (i=1:length(availableExt))

    if (strcmpi(Ext, availableExt{i}))

        FOUND=1;

        break;

    end

end

 

if (FOUND==0)

    h = msgbox('File type not supported!','Error','error');

    return;

end

 

set(handles.sliderRotate, 'Enable', 'on');

set(handles.sliderBright, 'Enable', 'on');

set(handles.sliderContrast, 'Enable', 'on');

set(handles.editPath, 'Visible', 'on');

set(handles.editSize, 'Visible', 'on');

set(handles.editComment, 'Visible', 'on');

 

 

info = imfinfo(handles.fullPath);

if (~isempty(info.Comment))

    % save current image comment (to be used later in image save)

    handles.currentImageComment = info.Comment{1};

else

    handles.currentImageComment = '';

end

 

set(handles.editSize, 'String', sprintf('SIZE (W x H) : %d x %d', info.Width, info.Height));

set(handles.editComment, 'String', sprintf('COMMENT: %s', handles.currentImageComment));

set(handles.editPath', 'String', handles.fullPath);

 

 

RGB = imread(handles.fullPath);

 

handles.RGB = RGB;

handles.RGB2 = RGB;

handles.fileLoaded = 1;

handles.fileLoaded2 = 0;

 

set(handles.axes1,'Visible','off'); set(handles.axes2,'Visible','off');

set(handles.axesHist1,'Visible','off'); set(handles.axesHist2,'Visible','off');

set(handles.textHist1, 'Visible', 'off');

axes(handles.axesHist2); cla;

set(handles.textHist2, 'Visible', 'off');

 

axes(handles.axes1); cla; imshow(RGB);

axes(handles.axes2); cla;

 

handles = updateHistograms(handles);

 

guidata(hObject, handles);

 

 

 

% --- Executes on button press in CopyButton.

function CopyButton_Callback(hObject, eventdata, handles)

% hObject    handle to CopyButton (see GCBO)

% eventdata  reserved - to be defined in a future version of MATLAB

% handles    structure with handles and user data (see GUIDATA)

 

if (handles.fileLoaded==1)

    handles.RGB2 = handles.RGB;

    axes(handles.axes2); imshow(handles.RGB2);

    handles.fileLoaded2 = 1;

    handles = updateHistograms(handles);

    guidata(hObject, handles);

else

    h = msgbox('No primary file has been loaded!','Error','error');

end

 

% --- Executes on button press in MedianButton.

function MedianButton_Callback(hObject, eventdata, handles)

% hObject    handle to MedianButton (see GCBO)

% eventdata  reserved - to be defined in a future version of MATLAB

% handles    structure with handles and user data (see GUIDATA)

 

if (handles.fileLoaded==1)

 

    [M,N,ttt] = size(handles.RGB);

 

    RUN = 1;

 

    while (RUN==1)

 

        prompt = {'Enter Median Row Factor (0-5%):','Enter Median Column Factor (0-5%):'};

        dlg_title = 'Enter Median Parameters:';

        num_lines = 1;

        def = {'2','2'};

        answer = inputdlg(prompt,dlg_title,num_lines,def);

       if (isempty(answer))

            return;

        end

 

        M1 = str2num(answer{1})/100;

        M2 = str2num(answer{2})/100;

 

        if ((str2num(answer{1})>=0) & (str2num(answer{1})<=5)) & ((str2num(answer{2})>=0) & (str2num(answer{2})<=5))

            RUN = 0;

        end

    end

 

    M1 = round(M1 * M);

    M2 = round(M2 * N);

 

    w = waitbar(0, 'Median filtering ... Please wait ...');

    handles.RGB2(:,:,1) = medfilt2(handles.RGB(:,:,1),[M1 M2]);

    waitbar(1/3, w);

    handles.RGB2(:,:,2) = medfilt2(handles.RGB(:,:,2),[M1 M2]);

    waitbar(2/3, w);

    handles.RGB2(:,:,3) = medfilt2(handles.RGB(:,:,3),[M1 M2]);

    close(w);

    axes(handles.axes2); imshow(handles.RGB2);

    handles.fileLoaded2 = 1;

    handles = updateHistograms(handles);

 

    guidata(hObject, handles);

else

    h = msgbox('No primary file has been loaded!','Error','error');

end

 

% --- Executes on button press in SharpButton.

function SharpButton_Callback(hObject, eventdata, handles)

% hObject    handle to SharpButton (see GCBO)

% eventdata  reserved - to be defined in a future version of MATLAB

% handles    structure with handles and user data (see GUIDATA)

 

if (handles.fileLoaded==1)

    H = fspecial('unsharp');

    handles.RGB2(:,:,1) = imfilter(handles.RGB(:,:,1),H,'replicate');

    handles.RGB2(:,:,2) = imfilter(handles.RGB(:,:,2),H,'replicate');

    handles.RGB2(:,:,3) = imfilter(handles.RGB(:,:,3),H,'replicate');

    axes(handles.axes2); imshow(handles.RGB2);

    handles.fileLoaded2 = 1;

    handles = updateHistograms(handles);

    guidata(hObject, handles);

else

    h = msgbox('No primary file has been loaded!','Error','error');

end

 

% --- Executes on button press in MotionButton.

function MotionButton_Callback(hObject, eventdata, handles)

% hObject    handle to MotionButton (see GCBO)

% eventdata  reserved - to be defined in a future version of MATLAB

% handles    structure with handles and user data (see GUIDATA)

 

if (handles.fileLoaded==1)

 

    [M,N,ttt] = size(handles.RGB);

    D = max(M,N);

 

    RUN = 1;

 

    while (RUN==1)

 

        prompt = {'Enter Motion Length (0-15%):','Enter Motion Angle (0-360):'};

        dlg_title = 'Enter Motion Parameters:';

        num_lines = 1;

        def = {'1','0'};

        answer = inputdlg(prompt,dlg_title,num_lines,def);

        if (isempty(answer))

            return;

        end

       

        M1 = str2num(answer{1})/100;

        M2 = str2num(answer{2});

 

        if ((str2num(answer{1})>=0) & (str2num(answer{1})<=15))

            RUN = 0;

        end

    end

 

    H = fspecial('motion',D * M1,M2);

    w = waitbar(0, 'Motion filtering ... Please wait ...');

    handles.RGB2(:,:,1) = imfilter(handles.RGB(:,:,1),H,'replicate');

    waitbar(1/3, w);

    handles.RGB2(:,:,2) = imfilter(handles.RGB(:,:,2),H,'replicate');

    waitbar(2/3, w);

    handles.RGB2(:,:,3) = imfilter(handles.RGB(:,:,3),H,'replicate');

    close(w);

    axes(handles.axes2); imshow(handles.RGB2);

    handles.fileLoaded2 = 1;

    handles = updateHistograms(handles);

    guidata(hObject, handles);

else

   h = msgbox('No primary file has been loaded!','Error','error');

end

 

% --- Executes on button press in GrayButton.

function GrayButton_Callback(hObject, eventdata, handles)

% hObject    handle to GrayButton (see GCBO)

% eventdata  reserved - to be defined in a future version of MATLAB

% handles    structure with handles and user data (see GUIDATA)

 

if (handles.fileLoaded==1)

    Gray = rgb2gray(handles.RGB);

    handles.RGB2(:,:,1) = Gray;

    handles.RGB2(:,:,2) = Gray;

    handles.RGB2(:,:,3) = Gray;

    axes(handles.axes2); imshow(handles.RGB2);

    handles.fileLoaded2 = 1;

    handles = updateHistograms(handles);

    guidata(hObject, handles);

else

    h = msgbox('No primary file has been loaded!','Error','error');

end

 

 

% --- Executes on button press in SaveButton.

function SaveButton_Callback(hObject, eventdata, handles)

% hObject    handle to SaveButton (see GCBO)

% eventdata  reserved - to be defined in a future version of MATLAB

% handles    structure with handles and user data (see GUIDATA)

 

 

if (handles.fileLoaded2==1)

    [file,path] = uiputfile('*.jpg','Save Secondary Image As');

    imwrite(handles.RGB2,[path file],'jpg');

else

    h = msgbox('No secondary file has been loaded!','Save Error','error');

end

 

 

% --- Executes on button press in ColorsButton.

function ColorsButton_Callback(hObject, eventdata, handles)

% hObject    handle to ColorsButton (see GCBO)

% eventdata  reserved - to be defined in a future version of MATLAB

% handles    structure with handles and user data (see GUIDATA)

 

if (handles.fileLoaded==1)

    RUN = 1;

 

    while (RUN==1)

 

        prompt = {'Enter threshold for RED (0-255):','Enter threshold for GREEN (0-255):','Enter threshold for BLUE (0-255):'};

        dlg_title = 'RGB Thresholds:';

        num_lines = 1;

        def = {'30','30','30'};

        answer = inputdlg(prompt,dlg_title,num_lines,def);

        if (isempty(answer))

            return;

        end

        T1 = str2num(answer{1});

        T2 = str2num(answer{2});

        T3 = str2num(answer{3});

       

 

        if ((T1>=0) & (T1<=256)) & ((T2>=0) && (T2<=256)) & ((T3>=0) && (T3<=256))

            RUN = 0;

        end

    end

   

    handles.RGB2 = filterColors(handles.RGB, T1, T2, T3, 5);

    axes(handles.axes2); imshow(handles.RGB2);

    handles.fileLoaded2 = 1;

    handles = updateHistograms(handles);

 

    guidata(hObject, handles);   

else

    h = msgbox('No primary file has been loaded!','Error','error');

end

 

 

% --- Executes on button press in ColorButton2.

function ColorButton2_Callback(hObject, eventdata, handles)

% hObject    handle to ColorButton2 (see GCBO)

% eventdata  reserved - to be defined in a future version of MATLAB

% handles    structure with handles and user data (see GUIDATA)

 

 

if (handles.fileLoaded==1)

    RUN = 1;

 

    while (RUN==1)

 

        prompt = {'Enter weight for RED (0-200%):','Enter weight for GREEN (0-200%):','Enter weight for BLUE (0-200%):'};

        dlg_title = 'Enter Color Weight Parameters:';

        num_lines = 1;

        def = {'100','100','100'};

        answer = inputdlg(prompt,dlg_title,num_lines,def);

        if (isempty(answer))

            return;

        end

        W1 = str2num(answer{1});

        W2 = str2num(answer{2});

        W3 = str2num(answer{3});

       

 

        if ((W1>=0) & (W1<=200)) & ((W2>=0) && (W2<=200)) & ((W3>=0) && (W3<=200))

            RUN = 0;

        end

    end

   

    handles.RGB2 = handles.RGB;

    R = double(handles.RGB2(:,:,1));

    G = double(handles.RGB2(:,:,2));

    B = double(handles.RGB2(:,:,3));

   

    R = R * W1 ./ 100;

    G = G * W2 ./ 100;

    B = B * W3 ./ 100;

   

    R(find(R>256)) = 256;

    G(find(G>256)) = 256;

    B(find(B>256)) = 256;

   

    handles.RGB2(:,:,1) = R;

    handles.RGB2(:,:,2) = G;

    handles.RGB2(:,:,3) = B;

   

    axes(handles.axes2); imshow(handles.RGB2);

    handles.fileLoaded2 = 1;

    handles = updateHistograms(handles);

    guidata(hObject, handles);   

else

    h = msgbox('No primary file has been loaded!','Error','error');

end

 

 

% --- Executes on button press in InvColorButton.

function InvColorButton_Callback(hObject, eventdata, handles)

% hObject    handle to InvColorButton (see GCBO)

% eventdata  reserved - to be defined in a future version of MATLAB

% handles    structure with handles and user data (see GUIDATA)

 

if (handles.fileLoaded==1)

       

    R = double(handles.RGB(:,:,1));

    G = double(handles.RGB(:,:,2));

    B = double(handles.RGB(:,:,3));

       

    handles.RGB2(:,:,1) = 256 - R;

    handles.RGB2(:,:,2) = 256 - G;

    handles.RGB2(:,:,3) = 256 - B;

   

    axes(handles.axes2); imshow(handles.RGB2);

    handles.fileLoaded2 = 1;

    handles = updateHistograms(handles);

    guidata(hObject, handles);   

else

    h = msgbox('No primary file has been loaded!','Error','error');

end

 

 

 

 

 

function editSize_Callback(hObject, eventdata, handles)

% hObject    handle to editSize (see GCBO)

% eventdata  reserved - to be defined in a future version of MATLAB

% handles    structure with handles and user data (see GUIDATA)

 

% Hints: get(hObject,'String') returns contents of editSize as text

%        str2double(get(hObject,'String')) returns contents of editSize as a double

 

 

% --- Executes during object creation, after setting all properties.

function editSize_CreateFcn(hObject, eventdata, handles)

% hObject    handle to editSize (see GCBO)

% eventdata  reserved - to be defined in a future version of MATLAB

% handles    empty - handles not created until after all CreateFcns called

 

% Hint: edit controls usually have a white background on Windows.

%       See ISPC and COMPUTER.

if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))

    set(hObject,'BackgroundColor','white');

end

 

 

 

function editComment_Callback(hObject, eventdata, handles)

% hObject    handle to editComment (see GCBO)

% eventdata  reserved - to be defined in a future version of MATLAB

% handles    structure with handles and user data (see GUIDATA)

 

% Hints: get(hObject,'String') returns contents of editComment as text

%        str2double(get(hObject,'String')) returns contents of editComment as a double

 

 

% --- Executes during object creation, after setting all properties.

function editComment_CreateFcn(hObject, eventdata, handles)

% hObject    handle to editComment (see GCBO)

% eventdata  reserved - to be defined in a future version of MATLAB

% handles    empty - handles not created until after all CreateFcns called

 

% Hint: edit controls usually have a white background on Windows.

%       See ISPC and COMPUTER.

if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))

    set(hObject,'BackgroundColor','white');

end

 

 

 

 

 

function editPath_Callback(hObject, eventdata, handles)

% hObject    handle to editPath (see GCBO)

% eventdata  reserved - to be defined in a future version of MATLAB

% handles    structure with handles and user data (see GUIDATA)

 

% Hints: get(hObject,'String') returns contents of editPath as text

%        str2double(get(hObject,'String')) returns contents of editPath as a double

 

 

% --- Executes during object creation, after setting all properties.

function editPath_CreateFcn(hObject, eventdata, handles)

% hObject    handle to editPath (see GCBO)

% eventdata  reserved - to be defined in a future version of MATLAB

% handles    empty - handles not created until after all CreateFcns called

 

% Hint: edit controls usually have a white background on Windows.

%       See ISPC and COMPUTER.

if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))

    set(hObject,'BackgroundColor','white');

end

 

 

 

 

% --- Executes on slider movement.

function sliderBright_Callback(hObject, eventdata, handles)

% hObject    handle to sliderBright (see GCBO)

% eventdata  reserved - to be defined in a future version of MATLAB

% handles    structure with handles and user data (see GUIDATA)

 

% Hints: get(hObject,'Value') returns position of slider

%        get(hObject,'Min') and get(hObject,'Max') to determine range of slider

set(handles.editBright,'String', sprintf('%10s:%4.0f%%', 'Brightness', 100*get(handles.sliderBright,'Value')));

 

 

% --- Executes during object creation, after setting all properties.

function sliderBright_CreateFcn(hObject, eventdata, handles)

% hObject    handle to sliderBright (see GCBO)

% eventdata  reserved - to be defined in a future version of MATLAB

% handles    empty - handles not created until after all CreateFcns called

 

% Hint: slider controls usually have a light gray background.

if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))

    set(hObject,'BackgroundColor',[.9 .9 .9]);

end

 

 

% --- Executes on slider movement.

function sliderContrast_Callback(hObject, eventdata, handles)

% hObject    handle to sliderContrast (see GCBO)

% eventdata  reserved - to be defined in a future version of MATLAB

% handles    structure with handles and user data (see GUIDATA)

 

% Hints: get(hObject,'Value') returns position of slider

%        get(hObject,'Min') and get(hObject,'Max') to determine range of slider

set(handles.editContrast,'String', sprintf('%10s:%4.0f%%', 'Contrast', 100*get(handles.sliderContrast,'Value')));

 

 

% --- Executes during object creation, after setting all properties.

function sliderContrast_CreateFcn(hObject, eventdata, handles)

% hObject    handle to sliderContrast (see GCBO)

% eventdata  reserved - to be defined in a future version of MATLAB

% handles    empty - handles not created until after all CreateFcns called

 

% Hint: slider controls usually have a light gray background.

if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))

    set(hObject,'BackgroundColor',[.9 .9 .9]);

end

 

 

 

function editBright_Callback(hObject, eventdata, handles)

% hObject    handle to editBright (see GCBO)

% eventdata  reserved - to be defined in a future version of MATLAB

% handles    structure with handles and user data (see GUIDATA)

 

% Hints: get(hObject,'String') returns contents of editBright as text

%        str2double(get(hObject,'String')) returns contents of editBright as a double

 

 

% --- Executes during object creation, after setting all properties.

function editBright_CreateFcn(hObject, eventdata, handles)

% hObject    handle to editBright (see GCBO)

% eventdata  reserved - to be defined in a future version of MATLAB

% handles    empty - handles not created until after all CreateFcns called

 

% Hint: edit controls usually have a white background on Windows.

%       See ISPC and COMPUTER.

if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))

    set(hObject,'BackgroundColor','white');

end

 

 

 

 

 

function editContrast_Callback(hObject, eventdata, handles)

% hObject    handle to editContrast (see GCBO)

% eventdata  reserved - to be defined in a future version of MATLAB

% handles    structure with handles and user data (see GUIDATA)

 

% Hints: get(hObject,'String') returns contents of editContrast as text

%        str2double(get(hObject,'String')) returns contents of editContrast as a double

 

 

% --- Executes during object creation, after setting all properties.

function editContrast_CreateFcn(hObject, eventdata, handles)

Информация о работе Построение графического интерфейса в системе Matlab