I need to detect text in grocey items . I already get the result in MATLAB . In matlab i run the image one by one in another folder. The problem now is i need to do gui . In gui i need to run all the images in one folder . How can i read the images one by one in one coding?
function varargout = PLISJADIGUI(varargin) % PLISJADIGUI MATLAB code for PLISJADIGUI.fig
% PLISJADIGUI, by itself, creates a new PLISJADIGUI or raises the existing
% singleton*.
%
% H = PLISJADIGUI returns the handle to a new PLISJADIGUI or the handle to
% the existing singleton*.
% % PLISJADIGUI('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in PLISJADIGUI.M with the given input arguments.
% % PLISJADIGUI('Property','Value',...) creates a new PLISJADIGUI or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before PLISJADIGUI_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to PLISJADIGUI_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 PLISJADIGUI
% Last Modified by GUIDE v2.5 27-Apr-2017 09:18:09
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @PLISJADIGUI_OpeningFcn, ... 'gui_OutputFcn', @PLISJADIGUI_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 PLISJADIGUI is made visible.
function PLISJADIGUI_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 PLISJADIGUI (see VARARGIN)
% Choose default command line output for PLISJADIGUI
handles.output = hObject; % Update handles structure
guidata(hObject, handles); % UIWAIT makes PLISJADIGUI wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = PLISJADIGUI_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 pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles) % hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) %here we load image
global im im2 [path,user_cance]=imgetfile(); im=imread(path); im2=im; axes(handles.axes1); imshow(im); % --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles) % hObject handle to pushbutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) %here we reset the image to original
global im2 axes(handles.axes1); imshow(im2); % --- Executes on button press in pushbutton3.
function pushbutton3_Callback(hObject, eventdata, handles) % hObject handle to pushbutton3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) global im colorImage = imread('cadbury.jpg'); I = rgb2gray(colorImage); % Detect MSER regions.
[mserRegions, mserConnComp] = detectMSERFeatures(I, ... 'RegionAreaRange',[200 8000],'ThresholdDelta',4); figure axes(handles.axes1); imshow(I) hold on plot(mserRegions, 'showPixelList', true,'showEllipses',false) title('MSER regions') hold off global im mserStats = regionprops(mserConnComp, 'BoundingBox', 'Eccentricity', ... 'Solidity', 'Extent', 'Euler', 'Image'); % Compute the aspect ratio using bounding box data.
bbox = vertcat(mserStats.BoundingBox); w = bbox(:,3); h = bbox(:,4); aspectRatio = w./h; % Threshold the data to determine which regions to remove. These thresholds
% may need to be tuned for other images.
filterIdx = aspectRatio' > 3; filterIdx = filterIdx | [mserStats.Eccentricity] > .995 ; filterIdx = filterIdx | [mserStats.Solidity] < .3; filterIdx = filterIdx | [mserStats.Extent] < 0.2 | [mserStats.Extent] > 0.9; filterIdx = filterIdx | [mserStats.EulerNumber] < -4; % Remove regions
mserStats(filterIdx) = []; mserRegions(filterIdx) = []; % Show remaining regions
figure axes(handles.axes1); imshow(I) hold on plot(mserRegions, 'showPixelList', true,'showEllipses',false) title('After Removing Non-Text Regions Based On Geometric Properties') hold off global im % Get a binary image of the a region, and pad it to avoid boundary effects
% during the stroke width computation.
regionImage = mserStats(6).Image; regionImage = padarray(regionImage, [1 1]); % Compute the stroke width image.
distanceImage = bwdist(~regionImage); skeletonImage = bwmorph(regionImage, 'thin', inf); strokeWidthImage = distanceImage; strokeWidthImage(~skeletonImage) = 0; % Show the region image alongside the stroke width image.
figure subplot(1,2,1) imagesc(regionImage) title('Region Image') subplot(1,2,2) imagesc(strokeWidthImage) title('Stroke Width Image') % Compute the stroke width variation metric
strokeWidthValues = distanceImage(skeletonImage); strokeWidthMetric = std(strokeWidthValues)/mean(strokeWidthValues); % Threshold the stroke width variation metric
strokeWidthThreshold = 0.4; strokeWidthFilterIdx = strokeWidthMetric > strokeWidthThreshold; % Process the remaining regions
for j = 1:numel(mserStats) regionImage = mserStats(j).Image; regionImage = padarray(regionImage, [1 1], 0); distanceImage = bwdist(~regionImage); skeletonImage = bwmorph(regionImage, 'thin', inf); strokeWidthValues = distanceImage(skeletonImage); strokeWidthMetric = std(strokeWidthValues)/mean(strokeWidthValues); strokeWidthFilterIdx(j) = strokeWidthMetric > strokeWidthThreshold; end % Remove regions based on the stroke width variation
mserRegions(strokeWidthFilterIdx) = []; mserStats(strokeWidthFilterIdx) = []; % Show remaining regions figure axes(handles.axes1); imshow(I) hold on plot(mserRegions, 'showPixelList', true,'showEllipses',false) title('After Removing Non-Text Regions Based On Stroke Width Variation') hold off global im % Get bounding boxes for all the regions
bboxes = vertcat(mserStats.BoundingBox); % Convert from the [x y width height] bounding box format to the [xmin ymin
% xmax ymax] format for convenience.
xmin = bboxes(:,1); ymin = bboxes(:,2); xmax = xmin + bboxes(:,3) - 1; ymax = ymin + bboxes(:,4) - 1; % Expand the bounding boxes by a small amount.
expansionAmount = 0.02; xmin = (1-expansionAmount) * xmin; ymin = (1-expansionAmount) * ymin; xmax = (1+expansionAmount) * xmax; ymax = (1+expansionAmount) * ymax; % Clip the bounding boxes to be within the image bounds
xmin = max(xmin, 1); ymin = max(ymin, 1); xmax = min(xmax, size(I,2)); ymax = min(ymax, size(I,1)); % Show the expanded bounding boxes
expandedBBoxes = [xmin ymin xmax-xmin+1 ymax-ymin+1]; IExpandedBBoxes = insertShape(colorImage,'Rectangle',expandedBBoxes,'LineWidth',3); figure imshow(IExpandedBBoxes) title('Expanded Bounding Boxes Text') % Compute the overlap ratio
overlapRatio = bboxOverlapRatio(expandedBBoxes, expandedBBoxes); % Set the overlap ratio between a bounding box and itself to zero to
% simplify the graph representation.
n = size(overlapRatio,1); overlapRatio(1:n+1:n^2) = 0; % Create the graph
g = graph(overlapRatio); % Find the connected text regions within the graph
componentIndices = conncomp(g); % Merge the boxes based on the minimum and maximum dimensions.
xmin = accumarray(componentIndices', xmin, [], @min); ymin = accumarray(componentIndices', ymin, [], @min); xmax = accumarray(componentIndices', xmax, [], @max); ymax = accumarray(componentIndices', ymax, [], @max); % Compose the merged bounding boxes using the [x y width height] format.
textBBoxes = [xmin ymin xmax-xmin+1 ymax-ymin+1]; % Remove bounding boxes that only contain one text region
numRegionsInGroup = histcounts(componentIndices); textBBoxes(numRegionsInGroup == 1, :) = []; % Show the final text detection result.
ITextRegion = insertShape(colorImage, 'Rectangle', textBBoxes,'LineWidth',3); figure axes(handles.axes1); imshow(ITextRegion) title('Detected Text') ocrtxt = ocr(I, textBBoxes); [ocrtxt.Text]
i just can load the image cadbury only . at pushbutton 3 how can i set to read all images process that i have for example which is i want to put image of cadbury,shampoo,toiletries and so on too. how can i do the same process in different image in one coding .
Best Answer