LESSER THE MARKS MORE IS THE HUNGER TO DO WELL AND YOU EXPLORE NEW WAYS TO DO THINGS BETTER. SO DONT WORRY ABOUT MARKS


Saturday, August 4, 2012

BIT PLANE PROCESSING FOR MEDICAL IMAGES WITH GUI


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

% Last Modified by GUIDE v2.5 15-Jun-2012 21:57:57

% Begin initialization code - DO NOT EDIT

gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @bitplane_ABHI_OpeningFcn, ...
                   'gui_OutputFcn',  @bitplane_ABHI_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 bitplane_ABHI is made visible.
function bitplane_ABHI_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 bitplane_ABHI (see VARARGIN)

% Choose default command line output for bitplane_ABHI
handles.fileLoaded = 0;
handles.fileLoaded2=0;
set(handles.axes1,'Visible','off');
set(handles.axes2,'Visible','off');
set(handles.axes3,'Visible','off');
set(handles.axes4,'Visible','off');
set(handles.axes5,'Visible','off');
set(handles.axes6,'Visible','off');
set(handles.axes7,'Visible','off');
set(handles.axes8,'Visible','off');
handles.output = hObject;


% Update handles structure
guidata(hObject, handles);

% UIWAIT makes bitplane_ABHI wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = bitplane_ABHI_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 button press in load.
function load_Callback(hObject, eventdata, handles)
% hObject    handle to load (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% 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)
     msgbox('File type not supported!','Error','error');
    return;
end

%info = imfinfo(handles.fullPath);
 %set(handles.editR1, 'String', sprintf('SIZE (W x H) : %d x %d', info.Width, info.Height));cla;
RGB=imread(handles.fullPath);
handles.RGB = RGB;
handles.fileLoaded = 1;
set(handles.axes1,'Visible','on');
axes(handles.axes1);cla; imshow(RGB);
guidata(hObject, handles);


% --- Executes on button press in crop.
function crop_Callback(hObject, eventdata, handles)
% hObject    handle to crop (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
crop=imcrop(handles.RGB);
handles.crop=crop;
axes(handles.axes1);imshow(handles.crop);
guidata(hObject,handles);


% --- Executes on button press in gray.
function gray_Callback(hObject, eventdata, handles)
% hObject    handle to gray (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
gray=rgb2gray(handles.crop);
%gray=im2double(gray);
handles.gray=gray;
axes(handles.axes1);cla;imshow(handles.gray);
guidata(hObject, handles);


% --- Executes on button press in bit1.
function bit1_Callback(hObject, eventdata, handles)
% hObject    handle to bit1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
[file,path] = uiputfile('*.jpg','Save Secondary Image As');
    imwrite(handles.gray,[path file],'jpg');
    guidata(hObject, handles);


% --- Executes on button press in bit2.
function bit2_Callback(hObject, eventdata, handles)
% hObject    handle to bit2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
[file,path] = uiputfile('*.jpg','Save Secondary Image As');
    imwrite(handles.gray,[path file],'jpg');
    guidata(hObject, handles);


% --- Executes on button press in bit3.
function bit3_Callback(hObject, eventdata, handles)
% hObject    handle to bit3 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
[file,path] = uiputfile('*.jpg','Save Secondary Image As');
    imwrite(handles.gray,[path file],'jpg');
    guidata(hObject, handles);


% --- Executes on button press in bit4.
function bit4_Callback(hObject, eventdata, handles)
% hObject    handle to bit4 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
[file,path] = uiputfile('*.jpg','Save Secondary Image As');
    imwrite(handles.gray,[path file],'jpg');
    guidata(hObject, handles);


% --- Executes on button press in bit5.
function bit5_Callback(hObject, eventdata, handles)
% hObject    handle to bit5 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
[file,path] = uiputfile('*.jpg','Save Secondary Image As');
    imwrite(handles.gray,[path file],'jpg');
    guidata(hObject, handles);


% --- Executes on button press in bit6.
function bit6_Callback(hObject, eventdata, handles)
% hObject    handle to bit6 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
[file,path] = uiputfile('*.jpg','Save Secondary Image As');
    imwrite(handles.gray,[path file],'jpg');
    guidata(hObject, handles);


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



% --- Executes on button press in bitplane_ABHI.
function bitplane_Callback(hObject, eventdata, handles)
% hObject    handle to bitplane_ABHI (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
[m n] = size(handles.gray);
f=handles.gray;
c = cell(1,8);
for i = 1:m
for j = 1:n
b = f(i,j);
if ( b >= 128)
b = b-128; c{1,1}(i,j) = 1;
else
c{1,1}(i,j) = 0;
end
if (b >= 64)
b = b - 64; c{1,2}(i,j) = 1;
else
c{1,2}(i,j) = 0;
end
if (b >= 32)
b = b - 32; c{1,3}(i,j) = 1;
else
c{1,3}(i,j) = 0;
end
if (b >= 16)
b = b - 16; c{1,4}(i,j) = 1;
else
c{1,4}(i,j) = 0;
end
if (b >= 8)
b = b - 8; c{1,5}(i,j) = 1;
else
c{1,5}(i,j) = 0;
end
if (b >= 4)
b = b - 4; c{1,6}(i,j) = 1;
else
c{1,6}(i,j) = 0;
end
if (b >= 2)
b = b - 2; c{1,7}(i,j) = 1;
else
c{1,3}(i,j) = 0;
end
if (b >= 1)
b = b - 1; c{1,8}(i,j) = 1;
else
c{1,8}(i,j) = 0;
end
end
end
f1 = c{1,1}; f2 = c{1,2}; f3 = c{1,3}; f4 = c{1,4};
f5 = c{1,5}; f6 = c{1,6};  f8 = c{1,8};
set(handles.axes2,'Visible','on');
axes(handles.axes2);cla; imshow(f1);
set(handles.axes3,'Visible','on');
axes(handles.axes3);cla; imshow(f2);
set(handles.axes4,'Visible','on');
axes(handles.axes4);cla; imshow(f3);
set(handles.axes5,'Visible','on');
axes(handles.axes5);cla; imshow(f4);
set(handles.axes6,'Visible','on');
axes(handles.axes6);cla; imshow(f5);
set(handles.axes7,'Visible','on');
axes(handles.axes7);cla; imshow(f6);
set(handles.axes8,'Visible','on');
axes(handles.axes8);cla; imshow(f8);
guidata(hObject,handles)

No comments:

Post a Comment