Image Processing With MATLAB Software

Introduction

The paper presents Matlab code for three questions. The first question tackles image processing mechanisms. It touches on average, Gaussian and medial filtering techniques. The second question presents a detailed user interface program from which users can open and execute files. The file choice, in this case, is audio. The third question is open-ended and presents code for image sharpening. Matlab contains inbuilt functions which are used to produce more detailed on images, otherwise known as sharpening.

Image Filtering Mechanisms

Image filtering is a technique for altering the size, shape, color, depth, smoothness, and other aspects of pictures. Essentially, it modifies the pixels of an image to turn it into the desired shape by utilizing many forms of graphical editing procedures using graphic design and editing software [1]. There are primarily two sorts of filters, and depending on the topic, there are other filtering strategies. Image filters are commonly used to reduce noise and improve image quality. Matlab comes with several functions for image filtering, which take several parameters. In the program below, the image is first converted into a single channel from which different averages are calculated: average, gaussian and medial filters. The results obtained are then filtered and displayed for comparison with the original image.

Table 1. Image filtering code snippet.

clear all;
close all;
clc;

% read image file to be processed
image_input = imread(‘test1.jpg’);

% Convert input image to single channel
image_input = rgb2gray(image_input);

% calculate the average filter value for the image
avarage_filter_value = fspecial(‘average’, [5 5]);

% Calculate the gausian filter value
gausian_filter_value = fspecial(‘gaussian’, [13 13]);

% Process image using the average filter value
B_filter_average_value = imfilter(A, avarage_filter_value);

% Use gaussian filter value to process image
B_gaussian_fulter_value = imfilter(A, gausian_filter_value);

% Use midian filter value to process image
B_median_filter_value = medfilt2(A, [9 9]);

% Display input and filtered results
figure, subplot(2, 2, 1), imshow(A), title(‘Initial input image’);
subplot(2, 2, 2), imshow(B_filter_average_value), title(‘Average filter input’);
subplot(2, 2, 3), imshow(B_gaussian_fulter_value), title(‘Gaussian filter input’);
subplot(2, 2, 4), imshow(B_median_filter_value), title(‘Midian filter output’);

Graphical User Interface

Graphical user interfaces (GUIs) allow users to operate software programs using a point-and-click interface, reducing the need for others to learn a language or input instructions in order to utilize it. MATLAB provides developers with the tools to develop GUI apps that can be shared with other Matlab projects, desktops, or even web applications. GUI is comprised of different visual objects such as windows, menus, toolbars, icons, texts, navigation menus, and many others. The user-program interaction is mainly achieved through mouse clicks, scrolling, screen touch, and toggle buttons. The source code for this section is provided in the appendix.

Open-Ended Question: Image Sharpening

Sharpening is a method of enhancing an image’s perceived sharpness. Photo editing programs of libraries cannot magically add any more features to an image once it has been captured; the real resolution remains set [1]. One may enlarge the file, but the techniques used by any image editor would reduce the clarity of the image features. In other words, increasing acutance is the only method to improve perceived sharpness. You should increase the edge contrast of your image if you want it to seem sharper.

Sharpening your image has three purposes: to eliminate blurring caused by camera faults or limitations, to bring attention to certain regions, and to improve readability. Any current camera’s RAW data are always slightly blurred [1]. Blur is introduced at every stage of the image capture process. Some definition is lost when the light goes through the lens elements, no matter how finely crafted they are. When sharpening an image, photo editing software and libraries average out the sharpest transitions to produce better results. A modest amount of blur is generated when the three separate color channels are interpolated to form the final image.

MATLAB uses an inbuilt function (imsharpen) to sharpen images as shown in the code snippet below.

Table 2. Image sharpening using Matlab code.

clear all; close all; clc;

% open image file
image_input_file = imread(‘test1.jpg’);

% Sharpen read image with different amount
sharpened_image_1 = imsharpen(image_input_file, ‘Amount’, 0.8);
sharpened_image_2 = imsharpen(image_input_file, ‘Amount’, 1.0);
sharpened_image_3 = imsharpen(image_input_file, ‘Amount’, 1.2);

% shown sharpened images
figure, subplot(2, 2, 1), imshow(image_input_file), title(‘Original image’);
subplot(2, 2, 2), imshow(sharpened_image_1), title(‘Sharpened image: Sharpness 0.8’);
subplot(2, 2, 3), imshow(sharpened_image_2), title(‘Sharpened image: Sharpness 1.0’);
subplot(2, 2, 4), imshow(sharpened_image_3), title(‘Sharpened image: Sharpness 1.5);

Conclusion

The paper is comprised of three main sections: image filtering, GUI development using Matlab and image sharing. Image sharpening is employed in changing the size, shape, smoothness and other image characteristics. The Matlab feature for image filtering is used to perform Gaussian, average and median filtering. The second used Matlab to develop a graphical user interface that can be used for various applications. The application is full of features such as file opening, text zooming and a toolbar. The third section implements an image sharpening program in Matlab. Sharpening your image has three purposes: to eliminate blurring caused by camera faults or limitations, to bring attention to certain regions, and to improve readability.

Reference

Abdulrahman, A., & Varol, S. (2020). A Review of Image Segmentation Using MATLAB Environment. In 2020 8th International Symposium on Digital Forensics and Security (ISDFS) (pp. 1-5). IEEE. Web.

Appendix

Test image

Test image used in the sharpening code
Image 1. Test image used in the sharpening code

Graphical user interface program

Table 3. Graphical user interface program.

function urepet

% Get screen size
screen_size = get(0,’ScreenSize’);

% Create the figure window
object_figure = figure(…
‘Visible’,’off’,…
‘Position’,[screen_size(3:4)/4+1,screen_size(3:4)/2],…
‘Name’,’Main Screen’,…
‘NumberTitle’,’off’,…
‘MenuBar’,’none’,…
‘RequestCloseFunction’,@figureRequestCloseFunction);

% create tool bar
custom_tool_bar = uitoolbar(object_figure);

% media play icons
icon_media_play = playicon;
icon_media_stop = stopicon;

% Create main buttons
media_button_open = uipushtool(custom_tool_bar,…
‘CData’,iconread(‘file_open.png’),…
‘TooltipString’,’Open Item’,…
‘Enable’,’on’,…
‘ClickedCallback’,@openButtonClickedCallBackFunction); %#ok<*NASGU>
media_button_save = uipushtool(custom_tool_bar,…
‘CData’,iconread(‘file_save.png’),…
‘TooltipString’,’Save Item’,…
‘Enable’,’off’);
media_button_play = uipushtool(custom_tool_bar,…
‘CData’,icon_media_play,…
‘TooltipString’,’Play Item’,…
‘Enable’,’off’,…
‘UserData’,struct(‘PlayIcon’,icon_media_play,’StopIcon’,icon_media_stop));

% Pointer, oom, toggle buttons
media_button_select = uitoggletool(custom_tool_bar,…
‘Separator’,’On’,…
‘CData’,iconread(‘tool_pointer.png’),…
‘TooltipString’,’Select This’,…
‘Enable’,’off’,…
‘ClickedCallBack’,@SelectCLickedCallBackFunction);
media_button_zoom = uitoggletool(custom_tool_bar,…
‘CData’,iconread(‘tool_zoom_in.png’),…
‘TooltipString’,’Zoom’,…
‘Enable’,’off’,…
‘ClickedCallBack’,@ZoomClickedCallbackFunction);
media_button_pan = uitoggletool(custom_tool_bar,…
‘CData’,iconread(‘tool_hand.png’),…
‘TooltipString’,’Pan’,…
‘Enable’,’off’,…
‘ClickedCallBack’,@panClickedCallBackFunction);

% Create window, parameters
main_button_urepet = uipushtool(custom_tool_bar,…
‘Separator’,’On’,…
‘CData’,main_icon,…
‘TooltipString’,’uREPET Button’,…
‘Enable’,’off’);
main_button_background = uitoggletool(custom_tool_bar,…
‘CData’,iconread(‘tool_font_bold.png’),…
‘TooltipString’,’Background Button’,…
‘Enable’,’off’,…
‘ClickedCallBack’,@BackGroundClickedCallBackFunction);
media_undo_icon = iconread(‘tool_rotate_3d.png’);
media_undo_icon(6:12,6:12,:) = NaN;
media_undo_button = uipushtool(custom_tool_bar,…
‘CData’,media_undo_icon,…
‘TooltipString’,’Undo Operation’,…
‘Enable’,’off’);

% axes for signals and spectrum
axes_signal = axes(…
‘OuterPosition’,[0,0.9,1,0.1],…
‘Visible’,’off’);
axes_spectrogram = axes(…
‘OuterPosition’,[0,0,1,0.9],…
‘Visible’,’off’);

% x-axis limits
linkaxes([axes_signal,axes_spectrogram],’x’)

% change mouse on spectrogram
EnterKeyFunction = @(figure_handle,currentPoint) set(figure_handle,’Pointer’,’ibeam’);
iptSetPointerBehavior(axes_signal,EnterKeyFunction);
iptPointerManager(object_figure);

% mouse over media
EnterKeyFunction = @(figure_handle,currentPoint) set(figure_handle,’Pointer’,’arrow’);
iptSetPointerBehavior(object_figure,EnterKeyFunction)
iptSetPointerBehavior(axes_spectrogram,EnterKeyFunction)
iptPointerManager(object_figure);

% initialize player
media_player_audio = audioplayer(0,80);

% figure = visible
object_figure.Visible = ‘on’;

% call back function for open button
function openButtonClickedCallBackFunction(~,~)
% dialog box to open files
[audio_file_name,audio_file_path] = uigetfile({‘*.mp3′;’*.wav’},…
‘MP3 or WAV audio files’);
if isequal(audio_file_name,0) || isequal(audio_file_path,0)
return
end
% Remove figures to allow creation of other objects
object_figure.RequestCloseFunction = ”;
% busy pointer
object_figure.Pointer = ‘watch’;
drawnow
% stop playing audio media
if isplaying(media_player_audio)
stop(media_player_audio)
end
% Clearaxes
cla(axes_signal)
axes_signal.Visible = ‘off’;
cla(axes_spectrogram)
axes_spectrogram.Visible = ‘off’;
drawnow
% Build name of file
full_file_audio = fullfile(audio_file_path,audio_file_name);
% audio and rate (Hz)
[audio_file_signal,audio_file_sample_rate] = audioread(full_file_audio);
% channels and samples
[number_of_samples,number_of_channels] = size(audio_file_signal);
% plot audio signal. disable mouse clicks
plot(axes_signal,…
1/audio_file_sample_rate:1/audio_file_sample_rate:number_of_samples/audio_file_sample_rate,…
audio_file_signal,…
‘PickableParts’,’none’);
% Update axes properties
axes_signal.XLim = [1,number_of_samples]/audio_file_sample_rate;
axes_signal.YLim = [-1,1];
axes_signal.XGrid = ‘on’;
axes_signal.Title.String = audio_file_name;
axes_signal.Title.Interpreter = ‘None’;
axes_signal.XLabel.String = ‘Time (s)’;
axes_signal.Layer = ‘top’;
axes_signal.UserData.PlotXLim = [1,number_of_samples]/audio_file_sample_rate;
axes_signal.UserData.SelectXLim = [1,number_of_samples]/audio_file_sample_rate;
drawnow
% Add the CQT toolbox folder to the search path
addpath(‘CQT_toolbox_2013’)
% Min & max Hz, number of channels
resolution_of_octave = 24;
min_freq_value = 27.5;
max_freq_value = audio_file_sample_rate/2;
% Initialize the CQT object and the spectrogram
cqt_audio_cell = cell(1,number_of_channels);
audio_spectrogram = [];
% Compute the CQT ,spectrogram for all channel
for index_of_channel = 1:number_of_channels %#ok<*FXUP>
cqt_audio_cell{index_of_channel}…
= cqt(audio_file_signal(:,index_of_channel),resolution_of_octave,audio_file_sample_rate,min_freq_value,max_freq_value);
audio_spectrogram = cat(3,audio_spectrogram,abs(cqt_audio_cell{index_of_channel}.c));
end
% Number of frequency channels and time frames
[frequency_number,number_of_times,~] = size(audio_spectrogram);
% Update the maximum frequency in Hz
max_freq_value = min_freq_value*2.^((frequency_number-1)/resolution_of_octave);
% Time range in seconds
media_play_time_range = [1,number_of_times]/number_of_times*number_of_samples/audio_file_sample_rate;
% Display the audio spectrogram
imagesc(axes_spectrogram,…
media_play_time_range,…
[(min_freq_value*2*frequency_number+max_freq_value)/(2*frequency_number+1),…
(max_freq_value*2*frequency_number+min_freq_value)/(2*frequency_number+1)],…
db(mean(audio_spectrogram,3)),…
‘PickableParts’,’none’);
% Update spectrogram axes properties
axes_spectrogram.YScale = ‘log’;
axes_spectrogram.YDir = ‘normal’;
axes_spectrogram.XGrid = ‘on’;
axes_spectrogram.Colormap = jet;
axes_spectrogram.Title.String = ‘Log-spectrogram’;
axes_spectrogram.XLabel.String = ‘Time (s)’;
axes_spectrogram.YLabel.String = ‘Frequency (Hz)’;
axes_spectrogram.ButtonDownFcn = @SpectrogramAxesButtonCallFunction;
drawnow
% Color limits
screen_color_limits = axes_spectrogram.CLim;
% playing audio object
media_player_audio = audioplayer(audio_file_signal,audio_file_sample_rate);
% play line
selectline(axes_signal)
PlayLineOnAxis(axes_signal,media_player_audio,media_button_play);
% click button call back function
media_button_play.ClickedCallback = {@PlayButtonClickedCallBackFunction,media_player_audio,axes_signal};
% Add key-press call back function
object_figure.KeyPressFcn = @keyPressedCallBackFunction;
% uREPET button call back function
main_button_urepet.ClickedCallback = @UrepetButtonClickedCallBackFunction;
% rectagle object
rect_obj = gobjects(0);
% convert Hz to indices
hertz_to_frequency = @(value_of_frequency) round(resolution_of_octave*log2(value_of_frequency/min_freq_value)+1);
seconds_to_time = @(value_of_time) round(value_of_time/(number_of_samples/audio_file_sample_rate)*number_of_times);
% Enable buttons
media_button_play.Enable = ‘on’;
media_button_select.Enable = ‘on’;
media_button_zoom.Enable = ‘on’;
media_button_pan.Enable = ‘on’;
main_button_urepet.Enable = ‘on’;
main_button_background.Enable = ‘on’;
main_button_background.State = ‘on’;
% activate select button
media_button_select.State = ‘on’;
% update mouse pointer
object_figure.Pointer = ‘arrow’;
drawnow
% close request function
object_figure.RequestCloseFunction = @figureRequestCloseFunction;
% Key-press callback function to the figure
function keyPressedCallBackFunction(~,~)
% if escape character
if ~strcmp(‘ ‘,object_figure.CurrentCharacter)
return
end
% if any media is playing
if isplaying(media_player_audio)
% stop
stop(media_player_audio)
else
% camples and sample rate
audio_file_sample_rate = media_player_audio.SampleRate;
number_of_samples = media_player_audio.TotalSamples;
% Plot data on axes
limits_of_plots = axes_signal.UserData.PlotXLim;
selected_limits = axes_signal.UserData.SelectXLim;
% calculate sample rate for audio
if selected_limits(1) == selected_limits(2)
% If select line
range_of_samples = [round((selected_limits(1)-limits_of_plots(1))*audio_file_sample_rate)+1,number_of_samples];
else
% If select region
range_of_samples = round((selected_limits-limits_of_plots(1))*audio_file_sample_rate+1);
end
% Play audio with given rates
play(media_player_audio,range_of_samples)
end
end
% Mouse-click function (spectrogram)
function SpectrogramAxesButtonCallFunction(~,~)
% mouse location
current_mouse_pointer_location = axes_spectrogram.CurrentPoint;
% if mouse is outside the axes
if current_mouse_pointer_location(1,1) < media_play_time_range(1) || current_mouse_pointer_location(1,1) >media_play_time_range(2) ||…
current_mouse_pointer_location(1,2) < min_freq_value || current_mouse_pointer_location(1,2) >max_freq_value
return
end
% If left click
if strcmp(object_figure.SelectionType,’normal’)
% Delete rectangle object
delete(rect_obj)
% Draw RIO from specified point
rect_obj = images.roi.Rectangle(‘Parent’,axes_spectrogram,…
‘DrawingArea’,[media_play_time_range(1),min_freq_value,diff(media_play_time_range),max_freq_value-min_freq_value]);
beginDrawingFromPoint(rect_obj,current_mouse_pointer_location(1,1:2));
end
end
% Clicked callback function for the uREPET button
function UrepetButtonClickedCallBackFunction(~,~)
% If rectangle not valid or empty
if isempty(rect_obj) || ~isvalid(rect_obj)
return
end
% Position of ROI
position_of_rectangle = rect_obj.Position;
%width=heithg=0
if all(~position_of_rectangle(3:4))
return
end
% Remove close request call back. Allows creation of other objects
object_figure.RequestCloseFunction = ”;
% update pointer to busy
object_figure.Pointer = ‘watch’;
drawnow
% stop playing audio player
if isplaying(media_player_audio)
stop(media_player_audio)
end
% add original audio to undo
audio_file_signal0 = audio_file_signal;
cqt_audio_cell0 = cqt_audio_cell;
% Frequency & time indices
indices_of_frequencies = hertz_to_frequency(position_of_rectangle(2)+[0,position_of_rectangle(4)]);
indeces_of_time = seconds_to_time(position_of_rectangle(1)+[0,position_of_rectangle(3)]);
% rectangle from spectrogram
audio_from_rectangle = audio_spectrogram(indices_of_frequencies(1):indices_of_frequencies(2),…
indeces_of_time(1):indeces_of_time(2),:);
size_of_rectangle = size(audio_from_rectangle);
% 2-D cross-correlation
correlation_of_audios = normxcorr2(mean(audio_from_rectangle,3),mean(audio_spectrogram,3));
% Remove zero padding parts
correlation_of_audios = correlation_of_audios(size_of_rectangle(1):end-size_of_rectangle(1)+1,…
size_of_rectangle(2):end-size_of_rectangle(2)+1);
correlation_size = size(correlation_of_audios);
% Max repetitions, min freq
number_of_repetitions = 10;
separation_of_Frequencies = 1;
separation_of_time = 1;
separation_of_Frequencies = separation_of_Frequencies*resolution_of_octave;
separation_of_time = seconds_to_time(separation_of_time);
correlation_of_audios(max(indices_of_frequencies(1)-separation_of_Frequencies,1):min(indices_of_frequencies(1)+separation_of_Frequencies,correlation_size(1)),…
max(indeces_of_time(1)-separation_of_time,1):min(indeces_of_time(1)+separation_of_time,correlation_size(2))) = 0;
% Loop over repetitions
for repet_index = 2:number_of_repetitions
% Frequency,time indices of the min repetition
[~,maximum_index] = max(correlation_of_audios(:));
[frequency_index,time_index] = ind2sub(correlation_size,maximum_index);

correlation_of_audios(max(frequency_index-separation_of_Frequencies,1):min(frequency_index+separation_of_Frequencies,correlation_size(1)),…
max(time_index-separation_of_time,1):min(time_index+separation_of_time,correlation_size(2))) = 0;
audio_from_rectangle = cat(4,audio_from_rectangle,…
audio_spectrogram(frequency_index:frequency_index+size_of_rectangle(1)-1,…
time_index:time_index+size_of_rectangle(2)-1,:));
end
% rectangles mask
audio_rectangle_mask = (min(median(audio_from_rectangle,4),audio_from_rectangle(:,:,:,1))+eps)./(audio_from_rectangle(:,:,:,1)+eps);
% If the background button is off, invert the mask
if strcmp(main_button_background.State,’off’)
audio_rectangle_mask = audio_rectangle_mask-1;
end
% Apply the mask to the CQT and spectrogram
audio_file_signal = zeros(number_of_samples,number_of_channels);
for index_of_channel = 1:number_of_channels
cqt_audio_cell{index_of_channel}.c(indices_of_frequencies(1):indices_of_frequencies(2),indeces_of_time(1):indeces_of_time(2))…
= audio_rectangle_mask(:,:,index_of_channel).*cqt_audio_cell{index_of_channel}.c(indices_of_frequencies(1):indices_of_frequencies(2),indeces_of_time(1):indeces_of_time(2));
audio_spectrogram(indices_of_frequencies(1):indices_of_frequencies(2),indeces_of_time(1):indeces_of_time(2),index_of_channel)…
= audio_rectangle_mask(:,:,index_of_channel).*audio_spectrogram(indices_of_frequencies(1):indices_of_frequencies(2),indeces_of_time(1):indeces_of_time(2),index_of_channel);
audio_file_signali = icqt(cqt_audio_cell{index_of_channel});
audio_file_signal(:,index_of_channel) = audio_file_signali(1:number_of_samples);
end
% Update the signal axes
index_of_channel = number_of_channels;
for child_index = 1:numel(axes_signal.Children)
if numel(axes_signal.Children(child_index).YData) == number_of_samples
axes_signal.Children(child_index).YData = audio_file_signal(:,index_of_channel);
index_of_channel = index_of_channel-1;
end
end
drawnow
% Update the spectrogram axes
axes_spectrogram.Children(end).CData(indices_of_frequencies(1):indices_of_frequencies(2),indeces_of_time(1):indeces_of_time(2))…
= db(mean(audio_spectrogram(indices_of_frequencies(1):indices_of_frequencies(2),indeces_of_time(1):indeces_of_time(2),:),3));
axes_spectrogram.CLim = screen_color_limits;
drawnow
% Update the audio player
media_player_audio = audioplayer(audio_file_signal,audio_file_sample_rate);
PlayLineOnAxis(axes_signal,media_player_audio,media_button_play);
media_button_play.ClickedCallback = {@PlayButtonClickedCallBackFunction,media_player_audio,axes_signal};
media_button_save.ClickedCallback = @SaveButtonClickedCallBackFunction;
media_undo_button.ClickedCallback = @UndoButtonClickedCallBackFunction;
% Enable nuttons
media_button_save.Enable = ‘on’;
media_undo_button.Enable = ‘on’;
object_figure.RequestCloseFunction = @figureRequestCloseFunction;
% Change pointer
object_figure.Pointer = ‘arrow’;
% Clicked callback function for the save button
function SaveButtonClickedCallBackFunction(~,~)
% Open dialog box to save file
[audio_file_name,audio_file_path] = uiputfile(‘*.wav*’,…
‘Save Audio as WAVE File’,’urepet_file.wav’);
if isequal(audio_file_name,0) || isequal(audio_file_path,0)
return
end
% file name
full_file_audio = fullfile(audio_file_path,audio_file_name);
% write audio file
audiowrite(audio_file,audio_file_signal,audio_file_sample_rate)
end
% undo button call back function
function UndoButtonClickedCallBackFunction(~,~)
% Disable button
media_undo_button.Enable = ‘off’;
audio_file_signal = audio_file_signal0;
cqt_audio_cell = cqt_audio_cell0;
audio_spectrogram = [];
for index_of_channel = 1:number_of_channels
audio_spectrogram = cat(3,audio_spectrogram,abs(cqt_audio_cell{index_of_channel}.c));
end
% Update axes
index_of_channel = number_of_channels;
for child_index = 1:numel(axes_signal.Children)
if numel(axes_signal.Children(child_index).YData) == number_of_samples
axes_signal.Children(child_index).YData = audio_file_signal(:,index_of_channel);
index_of_channel = index_of_channel-1;
end
end
drawnow
% Update spectrogram axes
axes_spectrogram.Children(end).CData(indices_of_frequencies(1):indices_of_frequencies(2),indeces_of_time(1):indeces_of_time(2))…
= db(mean(audio_spectrogram(indices_of_frequencies(1):indices_of_frequencies(2),indeces_of_time(1):indeces_of_time(2),:),3));
axes_spectrogram.CLim = screen_color_limits;
drawnow
% Update the audio player
media_player_audio = audioplayer(audio_file_signal,audio_file_sample_rate);
PlayLineOnAxis(axes_signal,media_player_audio,media_button_play);
media_button_play.ClickedCallback = {@PlayButtonClickedCallBackFunction,media_player_audio,axes_signal};
end
end
end

% Clicked callback function for the select button
function SelectCLickedCallBackFunction(~,~)
% update button status
media_button_select.State = ‘on’;
media_button_zoom.State = ‘off’;
media_button_pan.State = ‘off’;
zoom off
pan off
end

% Clicked callback function for the zoom button
function ZoomClickedCallbackFunction(~,~)
% update buttons
media_button_select.State = ‘off’;
media_button_zoom.State = ‘on’;
media_button_pan.State = ‘off’;
% enable zoom
zoom_object = zoom(object_figure);
zoom_object.Enable = ‘on’;
% zoom x axes only
setAxesZoomConstraint(zoom_object,axes_signal,’x’);
%update pan
pan off
end

% pan clicked call back function
function panClickedCallBackFunction(~,~)
% update buttons
media_button_select.State = ‘off’;
media_button_zoom.State = ‘off’;
media_button_pan.State = ‘on’;
zoom off
pan_object = pan(object_figure);
pan_object.Enable = ‘on’;
% set pan for x axis only
setAxesPanConstraint(pan_object,axes_signal,’x’);
end

% Clicked callback function for the background button
function BackGroundClickedCallBackFunction(~,~)
% change mouse depending on what is happening
if strcmp(main_button_background.State,’on’)
main_button_background.TooltipString = ‘Background’;
elseif strcmp(main_button_background.State,’off’)
main_button_background.TooltipString = ‘Foreground’;
end
end

% Close call back function
function figureRequestCloseFunction(~,~)
% stop playing life
if isplaying(media_player_audio)
stop(media_player_audio)
end
% close dialog box
user_answer = questdlg(‘Close window?’,…
‘Close window’,’Yes’,’No’,’Yes’);
switch user_answer
case ‘Yes’
delete(object_figure)
case ‘No’
return
end
end

end

% Read imatlab icon
function image_function_data = iconread(icon_name)

[image_function_data,~,image_transparency]…
= imread(fullfile(matlabroot,’toolbox’,’matlab’,’icons’,icon_name),’PNG’);

%image to double precision
image_function_data = im2double(image_function_data);

% Convert the 0 to NaNs
image_function_data(image_transparency==0) = NaN;

end

% play icon
function image_function_data = playicon

% upper half play triangle
image_function_data = [nan(2,16);[nan(6,3),kron(triu(nan(6,5)),ones(1,2)),nan(6,3)]];

% whole black play triangle image
image_function_data = repmat([image_function_data;image_function_data(end:-1:1,:)],[1,1,3]);

end

% stop icon
function image_function_data = stopicon

% black stop square
image_function_data = nan(16,16);
image_function_data(4:13,4:13) = 0;

% black stop square
image_function_data = repmat(image_function_data,[1,1,3]);

end

% Create project icon
function image_function_data = main_icon

image_function_data = nan(16,16,1);

% black letters
image_function_data(4:7,2) = 0;
image_function_data(7:8,3) = 0;
image_function_data(4:8,4:5) = 0;

image_function_data(2:8,7:8) = 0;
image_function_data([2,3,5,6],9) = 0;
image_function_data([3:5,7:8],10) = 0;

image_function_data(2:8,12:13) = 0;
image_function_data([2,3,5,7,8],14) = 0;
image_function_data([2,3,7,8],15) = 0;

image_function_data(10:16,2:3) = 0;
image_function_data([10,11,13,14],4) = 0;
image_function_data(11:13,5) = 0;

image_function_data(10:16,7:8) = 0;
image_function_data([10,11,13,15,16],9) = 0;
image_function_data([10,11,15,16],10) = 0;

image_function_data(10:11,12:15) = 0;
image_function_data(12:16,13:14) = 0;

% Make the image
image_function_data = repmat(image_function_data,[1,1,3]);

end

% select line for axes
function selectline(axes_signal)

% select line as an array for graphic objects initialization
line_selection = gobjects(3,1);

% mouse call back functions
axes_signal.ButtonDownFcn = @SignalAxesButtonDownFunction;

% Mouse-click callback function for the signal axes
function SignalAxesButtonDownFunction(~,~)
% mouse pointer location
current_mouse_pointer_location = axes_signal.CurrentPoint;
% plot limits
limits_of_plots = axes_signal.UserData.PlotXLim;
% return if point is out of limits
if current_mouse_pointer_location(1,1) < limits_of_plots(1) || current_mouse_pointer_location(1,1) >limits_of_plots(2) ||…
current_mouse_pointer_location(1,2) < -1 || current_mouse_pointer_location(1,2) >1
return
end
% handle current figure
object_figure = gcf;
% lect mouse type
type_of_mouse_selection = object_figure.SelectionType;
% left click
if strcmp(type_of_mouse_selection,’normal’)
% replace selected item
if ~isempty(line_selection)
delete(line_selection)
end
%first line on audio singnal
value_1_colour = 0.5*[1,1,1];
line_selection(1) = line(axes_signal,…
current_mouse_pointer_location(1,1)*[1,1],[-1,1],…
‘Color’,value_1_colour,…
‘ButtonDownFcn’,@SelectLineButtonFunction);
% second_line
color_value_2 = 0.75*[1,1,1];
line_selection(2) = line(axes_signal,…
current_mouse_pointer_location(1,1)*[1,1],[-1,1],…
‘Color’,color_value_2,…
‘ButtonDownFcn’,@SelectLineButtonFunction);
uistack(line_selection(2),’bottom’)
line_selection(3) = patch(axes_signal,…
current_mouse_pointer_location(1,1)*[1,1,1,1],[-1,1,1,-1],color_value_2,…
‘LineStyle’,’none’,…
‘PickableParts’,’none’);
uistack(line_selection(3),’bottom’)
% Change the pointer when the mouse moves
EnterKeyFunction = @(figure_handle, currentPoint) set(figure_handle,’Pointer’,’hand’);
iptSetPointerBehavior(line_selection(1),EnterKeyFunction);
iptSetPointerBehavior(line_selection(2),EnterKeyFunction);
iptSetPointerBehavior(axes_signal,EnterKeyFunction);
iptSetPointerBehavior(object_figure,EnterKeyFunction);
iptPointerManager(object_figure);
object_figure.WindowButtonMotionFcn = {@FigureWindowButtonCallBackFunction,line_selection(1)};
object_figure.WindowButtonUpFcn = @FigureWindowButtonUpFunction;
% Update the select limits
axes_signal.UserData.SelectXLim = current_mouse_pointer_location(1,1)*[1,1];
% right click
elseif strcmp(type_of_mouse_selection,’alt’)
% replace menu
if ~isempty(line_selection)
delete(line_selection)
end
% Update the select limits
axes_signal.UserData.SelectXLim = limits_of_plots;
end
% Mouse-click callback function
function SelectLineButtonFunction(object_handle,~)
% type of selection
type_of_mouse_selection = object_figure.SelectionType;
% If click left mouse button
if strcmp(type_of_mouse_selection,’normal’)
% Change the pointer when the mouse moves
EnterKeyFunction = @(figure_handle, currentPoint) set(figure_handle,’Pointer’,’hand’);
iptSetPointerBehavior(axes_signal,EnterKeyFunction);
iptSetPointerBehavior(object_figure,EnterKeyFunction);
iptPointerManager(object_figure);
% Add window button motion
object_figure.WindowButtonMotionFcn = {@FigureWindowButtonCallBackFunction,object_handle};
object_figure.WindowButtonUpFcn = @FigureWindowButtonUpFunction;
% right click
elseif strcmp(type_of_mouse_selection,’alt’)
% update menu
delete(line_selection)
% Update the select limits
axes_signal.UserData.SelectXLim = limits_of_plots;
end
end
% Window button motion callback function
function FigureWindowButtonCallBackFunction(~,~,line_selectioni)
% mouse pointer location
current_mouse_pointer_location = axes_signal.CurrentPoint;
% If the current point is out of the plot limits_of_plots

if current_mouse_pointer_location(1,1) < limits_of_plots(1)
current_mouse_pointer_location(1,1) = limits_of_plots(1);
elseif current_mouse_pointer_location(1,1) > limits_of_plots(2)
current_mouse_pointer_location(1,1) = limits_of_plots(2);
end
% Update the coordinates

line_selectioni.XData = current_mouse_pointer_location(1,1)*[1,1];
line_selection(3).XData = [line_selection(1).XData,line_selection(2).XData];
if line_selection(1).XData(1) ~= line_selection(2).XData(1)
% Change the color of the first line to match the color of the second line
line_selection(1).Color = color_value_2;
uistack(line_selection(1),’bottom’)
e
else
% Change the color of the first line back
line_selection(1).Color = value_1_colour;
uistack(line_selection(1),’top’)
end
end
% Window button up callback function for the figure
function FigureWindowButtonUpFunction(~,~)
% Change the pointer back when the mouse moves
EnterKeyFunction = @(figure_handle, currentPoint) set(figure_handle,’Pointer’,’ibeam’);
iptSetPointerBehavior(axes_signal,EnterKeyFunction);
iptPointerManager(object_figure);
EnterKeyFunction = @(figure_handle, currentPoint) set(figure_handle,’Pointer’,’arrow’);
iptSetPointerBehavior(object_figure,EnterKeyFunction);
iptPointerManager(object_figure);
% Coordinates
x_1_value = line_selection(1).XData(1);
x_2_value = line_selection(2).XData(1);
% Update the select limits
if x_1_value == x_2_value
axes_signal.UserData.SelectXLim = [x_1_value,x_1_value];
elseif x_1_value < x_2_value
axes_signal.UserData.SelectXLim = [x_1_value,x_2_value];
else
axes_signal.UserData.SelectXLim = [x_2_value,x_1_value];
end
% Remove the window button motion and up callback functions
object_figure.WindowButtonMotionFcn = ”;
object_figure.WindowButtonUpFcn = ”;
end
end

end

% Set a play line on the signal a
function PlayLineOnAxis(axes_signal,media_player_audio,media_button_play)

% media play buttons
icon_media_play = media_button_play.UserData.PlayIcon;
icon_media_stop = media_button_play.UserData.StopIcon;

% Sample rate in Hz
audio_file_sample_rate = media_player_audio.SampleRate;

% Get the plot limits
limits_of_plots = axes_signal.UserData.PlotXLim;

% Initialize the play line
play_media_line = [];

% Add callback functions
media_player_audio.StartFcn = @AudioPlaterStartFunction;
media_player_audio.StopFcn = @AudioPlaterStopFunction;
media_player_audio.TimerFcn = @AudioPlaterTimerFunction;

% Function to execute time
function AudioPlaterStartFunction(~,~)
media_button_play.CData = icon_media_stop;
media_button_play.TooltipString = ‘Stop’;
% Get the select limits
selected_limits = axes_signal.UserData.SelectXLim;
% Create a play line
play_media_line = line(axes_signal,selected_limits(1)*[1,1],[-1,1]);
end

% stop play call back function
function AudioPlaterStopFunction(~,~)
% update button status
media_button_play.CData = icon_media_play;
media_button_play.TooltipString = ‘Play’;
% remove play line
delete(play_media_line)
end

% Timer callback function
function AudioPlaterTimerFunction(~,~)

current_sample = media_player_audio.CurrentSample;
if current_sample > 1
% Update line
play_media_line.XData = (limits_of_plots(1)+current_sample/audio_file_sample_rate)*[1,1];
end
end

end

% Clicked callback function
function PlayButtonClickedCallBackFunction(~,~,media_player_audio,axes_signal)

% if playback is in progress
if isplaying(media_player_audio)
% Stop the audio
stop(media_player_audio)
else

audio_file_sample_rate = media_player_audio.SampleRate;
number_of_samples = media_player_audio.TotalSamples;
limits_of_plots = axes_signal.UserData.PlotXLim;
selected_limits = axes_signal.UserData.SelectXLim;
if selected_limits(1) == selected_limits(2)
range_of_samples = [round((selected_limits(1)-limits_of_plots(1))*audio_file_sample_rate)+1,number_of_samples];
else
range_of_samples = round((selected_limits-limits_of_plots(1))*audio_file_sample_rate+1);
end
play(media_player_audio,range_of_samples)
end

end

table data

Cite this paper

Select style

Reference

StudyCorgi. (2023, September 22). Image Processing With MATLAB Software. https://studycorgi.com/image-processing-with-matlab-software/

Work Cited

"Image Processing With MATLAB Software." StudyCorgi, 22 Sept. 2023, studycorgi.com/image-processing-with-matlab-software/.

* Hyperlink the URL after pasting it to your document

References

StudyCorgi. (2023) 'Image Processing With MATLAB Software'. 22 September.

1. StudyCorgi. "Image Processing With MATLAB Software." September 22, 2023. https://studycorgi.com/image-processing-with-matlab-software/.


Bibliography


StudyCorgi. "Image Processing With MATLAB Software." September 22, 2023. https://studycorgi.com/image-processing-with-matlab-software/.

References

StudyCorgi. 2023. "Image Processing With MATLAB Software." September 22, 2023. https://studycorgi.com/image-processing-with-matlab-software/.

This paper, “Image Processing With MATLAB Software”, was written and voluntary submitted to our free essay database by a straight-A student. Please ensure you properly reference the paper if you're using it to write your assignment.

Before publication, the StudyCorgi editorial team proofread and checked the paper to make sure it meets the highest standards in terms of grammar, punctuation, style, fact accuracy, copyright issues, and inclusive language. Last updated: .

If you are the author of this paper and no longer wish to have it published on StudyCorgi, request the removal. Please use the “Donate your paper” form to submit an essay.