Senin, 01 April 2013

[Comp Visi] Praktikum 3 - THRESHOLD

silakan dicopy gan.. ke notepad! biar aman gan..soalnya ada yang kena spasi turun tuh ...

++++++


% 1.Code Instalasi______________

function varargout = treshold(varargin)
.................
.............
if nargout > 0
varargout{1} = fig;
end

%Tambahkan Code disini
global global_max_value;
global global_min_value;
global_max_value = 255;
global_min_value = 0;

slider_step(1) = 1/255;
slider_step(2) = 10/255;
set(handles.slider_Max,'sliderstep', slider_step, 'max', 255, 'min', 0, 'Value', global_max_value);
set(handles.slider_Min,'sliderstep', slider_step, 'max', 255, 'min', 0, 'Value', global_min_value);
set(handles.edit_Max,'string', global_max_value);
set(handles.edit_Min,'string', global_min_value);

set(handles.listbox_DisplayScale, 'HandleVIsibility','off','Visible','off');
set(handles.text3.'Visible','off');
set(handles.axes1.'Visible','off');
set(handles.axes2.'Visible','off');
global loaded_image;
global image_filename;
global selected_scale;
global axes1_image;
global axes2_image;
global selected_scale;
loaded_image =[];
image_filename = '';
axes1_image = [];
axes2_image = [];
selected_scale = 1;


% 2.Function Slider______________

function varargout = slider_Max_Callback(h, eventdata,handles, varargin)
global global_max_value;
global global_min_value;
set(handles.text_messages,'string','');
max_value = round(get(handles.slider_Max,'Value'));
if (max_value >= global_min_value)
global_max_value = max_value;
set(handles.edit_Max,'string',global_max_value);
end
set(handles.slider_Max,'Value',global_max_value);
display_threshold(h, eventdata, handles, varargin);

function varargout = slider_Min_callback(h, eventdata, handles, varargin)
global global_max_value;
global global_min_value;
set(handles.text_messages,'string','');
min_value = round(get(handles.slider_Min,'Value'));
if (min_value <=global_max_value)
global_min_value = min_value;
set(handles.edit_Min,'string',global_min_value);
end
set(handles.slider_Min,'value',global_min_value);
display_threshold(h, eventdata, handles, varargin);

function varargout = edit_Max_Callback(h, eventdata, handles, varargin)
global global_max_value;
global global_min_value;
set(handles.text_messages,'string','');
max_value = str2double(get(handles.edit_Max,'string'));
if((max_value <= 255) & (max_value >= global_min_value) & (max_value~= NaN))
global_max_value = round(max_value);
set(handles.slider_Max,'Value',global_max_value);
end
set(handles.edit_Max,'string',global_max_value);
display_threshold(h, eventdata, handles, varargin);

function varargout = edit_Min_Callback(h, eventdata, handles, varargin)
global global_max_value;
global global_min_value;
set(handles.text_messages,'string','');
min_value = str2double(get(handles.edit_Min,'string'));
if((min_value >= 0) & (min_value <= global_max_value) & (min_value~= NaN))
global_min_value = round(min_value);
set(handles.Slider_Min,'string',global_min_value);
display_threshold(h, eventdata, handles, varargin);


% 2.Function Threshold_____________________

function display_threshold, eventdata, handles, varargin)
global global_max_value;
global global_min_value;
global axes1_image;
global axes2_image;
global selected_scale;

set(handles.text_messages,'string','');
axes(handles.axes2);
set(handles.axes2,'HandleVisibility','on', 'Visibile','on','Units','pixels');
if (selected_scale ~= 1)
set(handles.text_messages,'string','Finding thresholding regions);
axes2_image = threshold_grayscale_image(axes1_image,global_min_value,global_max_value);
message = strcat('Thresholded image between',num2str(global_min_value),' and ', ... num2str (global_max_value));
set(handles.text5,'string',message);
try
set(handles.text_messages,'string','Displaying Axes2 image');
warning off'
imshow(axes2_image);
warning on;
set(handles.text_messages,'string','');
catch
set(handles.text_messages,'string','Error displaying Axes2');
end
end
set(handles.axes2,'HandleVisibility','off');

%-----------------------------

function varargout = pushbutton_Overlap_Callback(h, eventdata, handles, varargin)
global axes1_image;
global axes2_image;
global selected_scale;
set(handles.text_messages,'string','');
%if (~isempty(axes1_image) & ~isempty(axes2_image) & (selected_scale ~=1))
if (~isempty(axes1_image) & ~isempty(axes2_image))
figure;
clf;
set(handles.text_messages,'string','Displaying images');
if (selected_scale == 1)
overlap_image (:,:,1) = uint8(double(axes1_image(:,:,1)) .*double(axes2_image));
overlap_image (:,:,2) = uint8(double(axes1_image(:,:,2)) .*double(axes2_image));
overlap_image (:,:,3) = uint8(double(axes1_image(:,:,3)) .*double(axes2_image));
else
overlap_image = uint8(double(axes2_image) .*double(axes1_image));
end

try
warning off;
imshow(overlap_image);
warning on;
set(handles.text_messages,'string','');
catch
set(handles.text_messages,'string','Errror displaying Overlapping images');
end
end

%-----------------------------

function varargout = pushbutton_save_Callback(h, eventdata, handles, varargin)
global axes2_image;
if ~isempty(axes2_image)
% save_as_file = strcat (get(handles.edit_Save_As,'string'),'.tif');
save_as_file = get(handles.edit_Save_As,'string');
message = strcat('Are You Sure That You Want To Save As : ',save_as_file);
reply = questdlg(message,'Saving File...','Yes','No','No');
if (strcmp(reply,'Yes') == 1)
set(handles.text_messages,'string','Starting to save thresholded image');
try
imwrite(axes2_image, save_as_file);
set(handles.text_messages,'string','');
msgbox('Save Completed','','none');
catch
set(handles.text_messages,'string',strcat('Error saving into',save_as_file));
end
end
end

Tidak ada komentar: