⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 irecovery.asv

📁 Block Recovery code - matlab
💻 ASV
字号:
function varargout = IRecovery(varargin)
% IRECOVERY M-file for IRecovery.fig
%      IRECOVERY, by itself, creates a new IRECOVERY or raises the existing
%      singleton*.
%
%      H = IRECOVERY returns the handle to a new IRECOVERY or the handle to
%      the existing singleton*.
%
%      IRECOVERY('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in IRECOVERY.M with the given input arguments.
%
%      IRECOVERY('Property','Value',...) creates a new IRECOVERY or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before IRecovery_OpeningFunction gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to IRecovery_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 IRecovery

% Last Modified by GUIDE v2.5 07-Dec-2007 12:05:45

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @IRecovery_OpeningFcn, ...
                   'gui_OutputFcn',  @IRecovery_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 IRecovery is made visible.
function IRecovery_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 IRecovery (see VARARGIN)

% Choose default command line output for IRecovery
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes IRecovery wait for user response (see UIRESUME)
% uiwait(handles.figure1);
    set(handles.btnSave,'enable','off');

% --- Outputs from this function are returned to the command line.
function varargout = IRecovery_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;



function edit1_Callback(hObject, eventdata, handles)
% hObject    handle to edit1 (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 edit1 as text
%        str2double(get(hObject,'String')) returns contents of edit1 as a double


% --- Executes during object creation, after setting all properties.
function edit1_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit1 (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 button press in btnBrowse.
function btnBrowse_Callback(hObject, eventdata, handles)
% hObject    handle to btnBrowse (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
    % selecting the image
    global I;
    [im1_name,im1_folder]=uigetfile({'*.jpg';'*.bmp'},'Select First Image');
    im1_path=[im1_folder,im1_name];    
    set(handles.edit1,'String',im1_path);
    axes(handles.axes2);
    I=imread(im1_path);
    imshow(I);
    title('Original Image');

% --- Executes on button press in btnNoise.
function btnNoise_Callback(hObject, eventdata, handles)
% hObject    handle to btnNoise (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

    % add noise to the source image
    set(handles.txtStatus,'String','Loading Noise...');
    global I;
    global IM;
    [m n]=size(IM);
    for i=5:12:m-12
        for j=5:12:n-12
            for x1=0:3
                for y1=0:3
                    IM(i+x1,j+y1)=0;
                end
            end
        end
    end
    %IM(1:20, 250:n)
    axes(handles.axes3);
    imshow(IM);
    title('Noise Loaded Image');
    figure;
    imshow(IM);
    set(handles.txtStatus,'String','Loading Noise Process Completed');    

% --- Executes on button press in btnExit.
function btnExit_Callback(hObject, eventdata, handles)
% hObject    handle to btnExit (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

    if isdeployed
        close all
        quit force
    else
        close all
    end 



% --- Executes on button press in btnRecover.
function btnRecover_Callback(hObject, eventdata, handles)
% hObject    handle to btnRecover (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

    % recover the noise block
    set(handles.txtStatus,'String','Recovering Block...');    
    global I;
    global IM;
    global IR;
    [m n]=size(IM); 
    IR=IBlockRec(IM);
    IR=IM;
    
    for i=5:12:m-12
         for j=5:12:n-12
             IR(i+0,j+0)=IR(i-1,j+0);
             IR(i+0,j+1)=IR(i-1,j+1);
             IR(i+0,j+2)=IR(i-1,j+2);
             IR(i+0,j+3)=IR(i-1,j+3);
             
             IR(i+3,j+0)=IR(i+4,j+0);
             IR(i+3,j+1)=IR(i+4,j+1);
             IR(i+3,j+2)=IR(i+4,j+2);
             IR(i+3,j+3)=IR(i+4,j+3);
             
             IR(i+1,j+0)=IR(i+1,j-1);
             IR(i+1,j+1)=IR(i+1,j-1);
             IR(i+2,j+0)=IR(i+2,j-1);
             IR(i+2,j+1)=IR(i+2,j-1);
             
             IR(i+1,j+2)=IR(i+1,j+4);
             IR(i+1,j+3)=IR(i+1,j+4);
             IR(i+2,j+2)=IR(i+2,j+4);
             IR(i+2,j+3)=IR(i+2,j+4);
             
%             for x1=0:3
%                 for y1=0:3
%                     IR(i+x1,j+y1)=IR(i-1,j-1);
%                 end
%             end
        end
    end
    
    axes(handles.axes2);
    imshow(IM);
    title('Noise Loaded Image');
    axes(handles.axes3);
    imshow(IR);
    title('Recovered Image');
    figure;
    imshow(IR);
    set(handles.txtStatus,'String','Completed Recovering the Missing Blocks');    
    set(handles.btnSave,'enable','on');


function txtStatus_Callback(hObject, eventdata, handles)
% hObject    handle to txtStatus (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 txtStatus as text
%        str2double(get(hObject,'String')) returns contents of txtStatus as a double


% --- Executes during object creation, after setting all properties.
function txtStatus_CreateFcn(hObject, eventdata, handles)
% hObject    handle to txtStatus (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 button press in btnGray.
function btnGray_Callback(hObject, eventdata, handles)
% hObject    handle to btnGray (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
    global I;
    global IM;
    set(handles.txtStatus,'String','Converting to Grayscale....'); 
    I=(.2989 * I(:,:,1)) + (.5870 * I(:,:,2)) + (.1140 * I(:,:,3));
    %IM=(.2989 * I(:,:,1)) + (.5870 * I(:,:,2)) + (.1140 * I(:,:,3));
    IM=I;
    axes(handles.axes3);
    imshow(IM);
    title('Grayscale Image');
    set(handles.txtStatus,'String','Grayscale Conversion Completed');    

    
    
% --- Executes on button press in btnSave.
function btnSave_Callback(hObject, eventdata, handles)
% hObject    handle to btnSave (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

    % save the recovered image
    global I;
    global IM;
    global IR;
    [im_name,im_folder]=uiputfile({'*.jpg';'*.bmp'},'Save File');
    im_path=[im_folder,im_name];
    imwrite(IR,im_path);
    set(handles.btnSave,'enable','off');
    set(handles.txtStatus,'String','Recovered Image has been Saved');    
    



% --- Executes on button press in btnCalPSNR.
function btnCalPSNR_Callback(hObject, eventdata, handles)
% hObject    handle to btnCalPSNR (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

    global I;
    global IM;
    global IR;
    [a b]=psnr(I,IR);
    

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -