Hello!
I'm trying to fill the "spottedRegions" edit field with the number of objects. In the simple script this already works for me with the output of N_objects (number of objects):
imageRGB = imread('shapes.jpg');imageGray = rgb2gray(imageRGB);imageBinary = imbinarize(imageGray); figure; imshow(imageBinary); title('Binary Image');[B,~,~] = bwboundaries(imageBinary);N_objects = length(B)-1 % number of shapes
shapes.jpg
I have done little in the App Designer so far. How do I get the N_objects displayed in my output field for "spottedRegions" – meaning after I hit OpenRGBimage?
The function for this button:
function OpenButtonPushed(app, event) imageRGB = imread('shapes.jpg'); imshow(imageRGB, 'Parent', app.UIAxes); end
Full code in app designer:
classdef shapesProperties < matlab.apps.AppBase % Properties that correspond to app components
properties (Access = public) UIFigure matlab.ui.Figure CreateBinaryImageButton matlab.ui.control.Button OpenButton matlab.ui.control.Button spottedRegionsEditField matlab.ui.control.EditField spottedRegionsEditFieldLabel matlab.ui.control.Label regionIndexSpinner matlab.ui.control.Spinner regionIndexSpinnerLabel matlab.ui.control.Label UIAxes2 matlab.ui.control.UIAxes UIAxes matlab.ui.control.UIAxes end methods (Access = public) end % Callbacks that handle component events
methods (Access = private) % Button pushed function: OpenButton
function OpenButtonPushed(app, event) imageRGB = imread('shapes.jpg'); imshow(imageRGB, 'Parent', app.UIAxes); end % Button pushed function: CreateBinaryImageButton
function CreateBinaryImageButtonPushed(app, event) imageRGB = imread('shapes.jpg'); % RGB --> Graustufen
imageGray = rgb2gray(imageRGB); % Graustufen --> Binärbild (Schwarz/Weiß)
imageBinary = im2bw(imageGray); imshow(imageBinary, 'Parent', app.UIAxes2); end % Value changed function: spottedRegionsEditField
function spottedRegionsEditFieldValueChanged(app, event) value = app.spottedRegionsEditField.Value; % value = N_objects ????
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.Position = [100 100 640 480]; app.UIFigure.Name = 'MATLAB App'; % Create UIAxes
app.UIAxes = uiaxes(app.UIFigure); title(app.UIAxes, 'RGB Image') app.UIAxes.Visible = 'off'; app.UIAxes.Position = [16 283 300 185]; % Create UIAxes2
app.UIAxes2 = uiaxes(app.UIFigure); title(app.UIAxes2, 'Binary Image') app.UIAxes2.Visible = 'off'; app.UIAxes2.Position = [315 283 300 185]; % Create regionIndexSpinnerLabel
app.regionIndexSpinnerLabel = uilabel(app.UIFigure); app.regionIndexSpinnerLabel.HorizontalAlignment = 'right'; app.regionIndexSpinnerLabel.Position = [366 230 68 22]; app.regionIndexSpinnerLabel.Text = 'regionIndex'; % Create regionIndexSpinner
app.regionIndexSpinner = uispinner(app.UIFigure); app.regionIndexSpinner.Position = [449 230 69 22]; % Create spottedRegionsEditFieldLabel
app.spottedRegionsEditFieldLabel = uilabel(app.UIFigure); app.spottedRegionsEditFieldLabel.HorizontalAlignment = 'right'; app.spottedRegionsEditFieldLabel.Position = [143 230 89 22]; app.spottedRegionsEditFieldLabel.Text = 'spottedRegions'; % Create spottedRegionsEditField
app.spottedRegionsEditField = uieditfield(app.UIFigure, 'text'); app.spottedRegionsEditField.ValueChangedFcn = createCallbackFcn(app, @spottedRegionsEditFieldValueChanged, true); app.spottedRegionsEditField.Position = [247 230 40 22]; % Create OpenButton
app.OpenButton = uibutton(app.UIFigure, 'push'); app.OpenButton.ButtonPushedFcn = createCallbackFcn(app, @OpenButtonPushed, true); app.OpenButton.Position = [12 230 108 22]; app.OpenButton.Text = 'OpenRGB-Image'; % Create CreateBinaryImageButton
app.CreateBinaryImageButton = uibutton(app.UIFigure, 'push'); app.CreateBinaryImageButton.ButtonPushedFcn = createCallbackFcn(app, @CreateBinaryImageButtonPushed, true); app.CreateBinaryImageButton.Position = [12 184 123 22]; app.CreateBinaryImageButton.Text = 'CreateBinary-Image'; % 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 = shapesProperties % Create UIFigure and components createComponents(app) % Register the app with App Designer
registerApp(app, app.UIFigure) 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 endend
Thank you very much in advance!
Michael
Best Answer