how do i solve this error: Undefined function 'imnoise' for input arguments of type 'uint8'.

7 views (last 30 days)
classdef app2 < matlab.apps.AppBase
% Properties that correspond to app components
properties (Access = public)
UIFigure matlab.ui.Figure
ShowOriginalSwitch matlab.ui.control.Switch
ShowOriginalSwitchLabel matlab.ui.control.Label
OKButton matlab.ui.control.Button
AdjustContrastLabel matlab.ui.control.Label
Slider_6 matlab.ui.control.Slider
Slider_5 matlab.ui.control.Slider
Slider_4 matlab.ui.control.Slider
Slider_3 matlab.ui.control.Slider
Slider_2 matlab.ui.control.Slider
Slider matlab.ui.control.Slider
NoiseSlider matlab.ui.control.Slider
NoiseSliderLabel matlab.ui.control.Label
BrowseButton matlab.ui.control.Button
ImageEditField matlab.ui.control.EditField
ImageEditFieldLabel matlab.ui.control.Label
PhotoEditorLabel matlab.ui.control.Label
UIAxes matlab.ui.control.UIAxes
end
properties (Access = private)
Image
Modified
TempEffect
Noise
Exit
LowR
LowG
LowB
HighR
HighG
HighB
end
% Callbacks that handle component events
methods (Access = private)
% Code that executes after component creation
function startupFcn(app)
title(app.UIAxes,[]);
xlabel(app.UIAxes,[]);
ylabel(app.UIAxes,[]);
app.UIAxes.XAxis.TickLabels= {};
app.UIAxes.YAxis.TickLabels= {};
app.Exit=0;
app.LowR=0.2;
app.LowG=0.3;
app.LowB=0;
app.HighR=0.6;
app.HighG=0.7;
app.HighB=1;
end
% Button pushed function: BrowseButton
function BrowseButtonPushed(app, event)
[filename,pathname]=uigetfile({'*.jpg';'*.png';'*.bmp';'*.gif';'*.*'},'File Selector');
app.ImageEditField.Value=strcat(pathname,filename);
app.Image=imread(app.ImageEditField.Value);
app.Modified=app.Image;
I=imshow(app.Modified,'Parent',app.UIAxes,...
'XData', [1 app.UIAxes.Position(3)], ...
'YData', [1, app.UIAxes.Position(4)]);
app.UIAxes.XLim=[0 I.XData(2)];
app.UIAxes.YLim=[0 I.YData(2)];
app.UIFigure.Visible='off';
app.UIFigure.Visible='on';
end
% Value changed function: NoiseSlider
function NoiseSliderValueChanged(app, event)
app.Noise = app.NoiseSlider.Value;
app.TempEffect=app.Modified;
if app.Noise> 0
app.TempEffect= imnoise(app.Modified,'gaussian',app.Noise);
I=imshow(app.TempEffect,'Parent',app.UIAxes,...
'XData', [1 app.UIAxes.Position(3)], ...
'YData', [1, app.UIAxes.Position(4)]);
app.UIAxes.XLim=[0 I.XData(2)];
app.UIAxes.YLim=[0 I.YData(2)];
else
app.TempEffect=app.Modified;
I=imshow(app.TempEffect,'Parent',app.UIAxes,...
'XData', [1 app.UIAxes.Position(3)], ...
'YData', [1, app.UIAxes.Position(4)]);
app.UIAxes.XLim=[0 I.XData(2)];
app.UIAxes.YLim=[0 I.YData(2)];
end
app.Exit=1;
end
% Value changed function: ShowOriginalSwitch
function ShowOriginalSwitchValueChanged(app, event)
if app.Exit==1
app.Modified= app.TempEffect;
app.Exit=0;
end
value = app.ShowOriginalSwitch.Value;
if strcmp(value,'On')==1
I=imshow(app.Image,'Parent',app.UIAxes,...
'XData', [1 app.UIAxes.Position(3)], ...
'YData', [1, app.UIAxes.Position(4)]);
app.UIAxes.XLim=[0 I.XData(2)];
app.UIAxes.YLim=[0 I.YData(2)];
else
I= imshow(app.Modified,'Parent',app.UIAxes,...
'XData', [1 app.UIAxes.Position(3)], ...
'YData', [1, app.UIAxes.Position(4)]);
app.UIAxes.XLim=[0 I.XData(2)];
app.UIAxes.YLim=[0 I.YData(2)];
end
end
% Value changed function: Slider
function SliderValueChanged(app, event)
app.LowR = app.Slider.Value;
app.TempEffect=imadjust(app.Modified,[app.LowR app.LowG app.LowB; app.HighR app.HighG app.HighB], []);
I= imshow(app.TempEffect,'Parent',app.UIAxes,...
'XData', [1 app.UIAxes.Position(3)], ...
'YData', [1, app.UIAxes.Position(4)]);
app.UIAxes.XLim=[0 I.XData(2)];
app.UIAxes.YLim=[0 I.YData(2)];
end
% Value changed function: Slider_2
function Slider_2ValueChanged(app, event)
app.LowG = app.Slider_2.Value;
app.TempEffect=imadjust(app.Modified,[app.LowR app.LowG app.LowB; app.HighR app.HighG app.HighB], []);
I= imshow(app.TempEffect,'Parent',app.UIAxes,...
'XData', [1 app.UIAxes.Position(3)], ...
'YData', [1, app.UIAxes.Position(4)]);
app.UIAxes.XLim=[0 I.XData(2)];
app.UIAxes.YLim=[0 I.YData(2)];
end
% Value changed function: Slider_3
function Slider_3ValueChanged(app, event)
app.LowB = app.Slider_3.Value;
app.TempEffect=imadjust(app.Modified,[app.LowR app.LowG app.LowB; app.HighR app.HighG app.HighB], []);
I= imshow(app.TempEffect,'Parent',app.UIAxes,...
'XData', [1 app.UIAxes.Position(3)], ...
'YData', [1, app.UIAxes.Position(4)]);
app.UIAxes.XLim=[0 I.XData(2)];
app.UIAxes.YLim=[0 I.YData(2)];
end
% Value changed function: Slider_4
function Slider_4ValueChanged(app, event)
app.HighR = app.Slider_4.Value;
app.TempEffect=imadjust(app.Modified,[app.LowR app.LowG app.LowB; app.HighR app.HighG app.HighB], []);
I= imshow(app.TempEffect,'Parent',app.UIAxes,...
'XData', [1 app.UIAxes.Position(3)], ...
'YData', [1, app.UIAxes.Position(4)]);
app.UIAxes.XLim=[0 I.XData(2)];
app.UIAxes.YLim=[0 I.YData(2)];
end
% Value changed function: Slider_5
function Slider_5ValueChanged(app, event)
app.HighG = app.Slider_5.Value;
app.TempEffect=imadjust(app.Modified,[app.LowR app.LowG app.LowB; app.HighR app.HighG app.HighB], []);
I= imshow(app.TempEffect,'Parent',app.UIAxes,...
'XData', [1 app.UIAxes.Position(3)], ...
'YData', [1, app.UIAxes.Position(4)]);
app.UIAxes.XLim=[0 I.XData(2)];
app.UIAxes.YLim=[0 I.YData(2)];
end
% Value changed function: Slider_6
function Slider_6ValueChanged(app, event)
app.HighB = app.Slider_6.Value;
app.TempEffect=imadjust(app.Modified,[app.LowR app.LowG app.LowB; app.HighR app.HighG app.HighB], []);
I= imshow(app.TempEffect,'Parent',app.UIAxes,...
'XData', [1 app.UIAxes.Position(3)], ...
'YData', [1, app.UIAxes.Position(4)]);
app.UIAxes.XLim=[0 I.XData(2)];
app.UIAxes.YLim=[0 I.YData(2)];
end
% Button pushed function: OKButton
function OKButtonPushed(app, event)
app.Modified=app.TempEffect;
I= imshow(app.Modified,'Parent',app.UIAxes,...
'XData', [1 app.UIAxes.Position(3)], ...
'YData', [1, app.UIAxes.Position(4)]);
app.UIAxes.XLim=[0 I.XData(2)];
app.UIAxes.YLim=[0 I.YData(2)];
end
end
% Component initialization
methods (Access = private)
% Create UIFigure and components
function createComponents(app)
% Create UIFigure and hide until all components are created
app.UIFigure = uifigure('Visible', 'off');
app.UIFigure.Color = [0.6353 0.0784 0.1843];
app.UIFigure.Position = [100 100 852 480];
app.UIFigure.Name = 'MATLAB App';
% Create UIAxes
app.UIAxes = uiaxes(app.UIFigure);
title(app.UIAxes, 'Title')
xlabel(app.UIAxes, 'X')
ylabel(app.UIAxes, 'Y')
zlabel(app.UIAxes, 'Z')
app.UIAxes.Position = [492 167 337 237];
% Create PhotoEditorLabel
app.PhotoEditorLabel = uilabel(app.UIFigure);
app.PhotoEditorLabel.HorizontalAlignment = 'center';
app.PhotoEditorLabel.FontSize = 18;
app.PhotoEditorLabel.FontColor = [1 1 1];
app.PhotoEditorLabel.Position = [292 418 127 35];
app.PhotoEditorLabel.Text = 'Photo Editor ';
% Create ImageEditFieldLabel
app.ImageEditFieldLabel = uilabel(app.UIFigure);
app.ImageEditFieldLabel.HorizontalAlignment = 'right';
app.ImageEditFieldLabel.FontColor = [1 1 1];
app.ImageEditFieldLabel.Position = [15 380 42 22];
app.ImageEditFieldLabel.Text = 'Image ';
% Create ImageEditField
app.ImageEditField = uieditfield(app.UIFigure, 'text');
app.ImageEditField.Position = [72 377 307 27];
% Create BrowseButton
app.BrowseButton = uibutton(app.UIFigure, 'push');
app.BrowseButton.ButtonPushedFcn = createCallbackFcn(app, @BrowseButtonPushed, true);
app.BrowseButton.Position = [380 378 82 26];
app.BrowseButton.Text = 'Browse';
% Create NoiseSliderLabel
app.NoiseSliderLabel = uilabel(app.UIFigure);
app.NoiseSliderLabel.HorizontalAlignment = 'right';
app.NoiseSliderLabel.FontColor = [1 1 1];
app.NoiseSliderLabel.Position = [16 330 36 22];
app.NoiseSliderLabel.Text = 'Noise';
% Create NoiseSlider
app.NoiseSlider = uislider(app.UIFigure);
app.NoiseSlider.Limits = [0 1];
app.NoiseSlider.ValueChangedFcn = createCallbackFcn(app, @NoiseSliderValueChanged, true);
app.NoiseSlider.Position = [73 339 378 7];
% Create Slider
app.Slider = uislider(app.UIFigure);
app.Slider.Limits = [0 0.5];
app.Slider.Orientation = 'vertical';
app.Slider.ValueChangedFcn = createCallbackFcn(app, @SliderValueChanged, true);
app.Slider.Position = [19 30 7 203];
app.Slider.Value = 0.2;
% Create Slider_2
app.Slider_2 = uislider(app.UIFigure);
app.Slider_2.Limits = [0 0.5];
app.Slider_2.Orientation = 'vertical';
app.Slider_2.ValueChangedFcn = createCallbackFcn(app, @Slider_2ValueChanged, true);
app.Slider_2.Position = [76 30 7 203];
app.Slider_2.Value = 0.3;
% Create Slider_3
app.Slider_3 = uislider(app.UIFigure);
app.Slider_3.Limits = [0 0.5];
app.Slider_3.Orientation = 'vertical';
app.Slider_3.ValueChangedFcn = createCallbackFcn(app, @Slider_3ValueChanged, true);
app.Slider_3.Position = [132 30 7 203];
% Create Slider_4
app.Slider_4 = uislider(app.UIFigure);
app.Slider_4.Limits = [0.5 1];
app.Slider_4.Orientation = 'vertical';
app.Slider_4.ValueChangedFcn = createCallbackFcn(app, @Slider_4ValueChanged, true);
app.Slider_4.Position = [225 30 7 203];
app.Slider_4.Value = 0.6;
% Create Slider_5
app.Slider_5 = uislider(app.UIFigure);
app.Slider_5.Limits = [0.5 1];
app.Slider_5.Orientation = 'vertical';
app.Slider_5.ValueChangedFcn = createCallbackFcn(app, @Slider_5ValueChanged, true);
app.Slider_5.Position = [281 30 7 203];
app.Slider_5.Value = 0.7;
% Create Slider_6
app.Slider_6 = uislider(app.UIFigure);
app.Slider_6.Limits = [0.5 1];
app.Slider_6.Orientation = 'vertical';
app.Slider_6.ValueChangedFcn = createCallbackFcn(app, @Slider_6ValueChanged, true);
app.Slider_6.Position = [344 30 7 203];
app.Slider_6.Value = 1;
% Create AdjustContrastLabel
app.AdjustContrastLabel = uilabel(app.UIFigure);
app.AdjustContrastLabel.FontSize = 18;
app.AdjustContrastLabel.FontColor = [1 1 1];
app.AdjustContrastLabel.Position = [138 247 133 28];
app.AdjustContrastLabel.Text = 'Adjust Contrast ';
% Create OKButton
app.OKButton = uibutton(app.UIFigure, 'push');
app.OKButton.ButtonPushedFcn = createCallbackFcn(app, @OKButtonPushed, true);
app.OKButton.FontWeight = 'bold';
app.OKButton.Position = [405 60 33 139];
app.OKButton.Text = 'OK';
% Create ShowOriginalSwitchLabel
app.ShowOriginalSwitchLabel = uilabel(app.UIFigure);
app.ShowOriginalSwitchLabel.HorizontalAlignment = 'center';
app.ShowOriginalSwitchLabel.FontColor = [1 1 1];
app.ShowOriginalSwitchLabel.Position = [473 19 79 22];
app.ShowOriginalSwitchLabel.Text = 'Show Original';
% Create ShowOriginalSwitch
app.ShowOriginalSwitch = uiswitch(app.UIFigure, 'slider');
app.ShowOriginalSwitch.ValueChangedFcn = createCallbackFcn(app, @ShowOriginalSwitchValueChanged, true);
app.ShowOriginalSwitch.FontColor = [1 1 1];
app.ShowOriginalSwitch.Position = [584 20 45 20];
% Show the figure after all components are created
app.UIFigure.Visible = 'on';
end
end
% App creation and deletion
methods (Access = public)
% Construct app
function app = app2
% Create UIFigure and components
createComponents(app)
% Register the app with App Designer
registerApp(app, app.UIFigure)
% Execute the startup function
runStartupFcn(app, @startupFcn)
if nargout == 0
clear app
end
end
% Code that executes before app deletion
function delete(app)
% Delete UIFigure when app is deleted
delete(app.UIFigure)
end
end
end

Answers (1)

Steven Lord
Steven Lord on 21 Jan 2023
The imnoise function is part of Image Processing Toolbox. Check the output of the ver function to determine if you have this toolbox installed. If it is not listed in the ver output you will not be able to use this function.

Categories

Find more on Develop Apps Using App Designer in Help Center and File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!