Print Page | Close Window

GUI for matlab code

Printed From: ProjectsQA
Category: Projects Forum
Forum Name: MATLAB Projects
Forum Discription: Projects and discussion on various areas of Matlab like Computer Vision, Image Processing, Signal Processing, Wireless Communication, Deep Learning, Data Analytics, Robotics, Control Systems
Printed Date: 22-Feb-2020 at 12:00pm

Topic: GUI for matlab code
Posted By: LokeshNash
Subject: GUI for matlab code
Date Posted: 06-Feb-2018 at 6:47pm
    can anyone help me to develop GUI(graphic user interface) for my matlab code for retinal image code is used to detect optic disc and exudate in retinal images using contour techniques

    clear all
    close all
    %% Read images.
    for count = 32:32
    name = ['Images 1\' int2str(count) '.tif'];
    img = imread(name);
    res_img = imresize(img,[256 256]);
    gr_img = rgb2gray(res_img);
    figure(1),imshow(gr_img),title('Input Image')
    h = fspecial('unsharp');
    filt_img = imfilter(res_img:),:,2),h);
    h = fspecial('disk',4);
    filt_img = imfilter(filt_img,h);
    figure(2),imshow(filt_img),title('Filtered Image')
    bw = im2bw(filt_img,0.43);
    % figure(3),imshow(bw),title('BW Image')
    % pause(0.2)
    se = strel('disk',5);
    BW_erod = imopen(bw,se);
    se = strel('disk',5);
    BW_dil = imdilate(BW_erod,se);
    % figure(4),imshow(BW_dil),title('Optic Disc')
    % pause(0.2)
    [L num] = bwlabel(BW_dil);
    if num == 0
    % disp('1:Optic Disc - Not Spotted')
    newstats = [];
    elseif num > 1
    newstats = [];
    stats = regionprops(L,'basic');
    for count2 = 1:length(stats)
    if ((stats(count2).Centroid(1) >= 75 && stats(count2).Centroid(1) <= 110) || ...
    (stats(count2).Centroid(1) >= 160 && stats(count2).Centroid(1) <= 190)) && ...
    (stats(count2).Centroid(2) >= 110 && stats(count2).Centroid(2) <= 145)
    newstats = stats(count2);
    stats = regionprops(L,'basic');
    if stats.Centroid(2) < 100 || stats.Centroid(2) > 150
    % disp('3:Optic Disc - Not Spotted')
    newstats = [];
    newstats = stats;
    if ~isempty(newstats)
    if newstats.BoundingBox(3) < 50
    newstats.BoundingBox(1) = newstats.BoundingBox(1) - ...
    (50 - newstats.BoundingBox(3))/2;
    newstats.BoundingBox(3) = 50;
    if newstats.BoundingBox(4) < 50
    newstats.BoundingBox(2) = newstats.BoundingBox(2) - ...
    (50 - newstats.BoundingBox(4))/2;
    newstats.BoundingBox(4) = 50;
    if newstats.BoundingBox(3) > 100
    newstats.BoundingBox(3) = 100;
    if newstats.BoundingBox(4) > 140
    newstats.BoundingBox(2) = newstats.BoundingBox(2) + 20;
    newstats.BoundingBox(4) = 110;

    region = imcrop(gr_img,newstats.BoundingBox);

    uiloc = find(any(region<3));

    if isempty(uiloc)
    ROI = region;
    elseif uiloc(1) == 1
    ROI = region:),uiloc(length(uiloc))+1:end);
    ROI = region:),1:uiloc(1)-1);
    % figure(5),imshow(ROI),title('Input to Contour detection')
    % pause(0.5)
    [ubin c xarr yarr cmat wdt] = test_activecontour('ODisc.tif',0,6);

    %% Applying Correlation to find segmented region..
    disp('Computing Correlation...')
    val = zeros(size(gr_img,1)-size(ROI,1),size(gr_img,2)-size(ROI,2));
    for i = 1:size(gr_img,1)-size(ROI,1)
    for j = 1:size(gr_img,2)-size(ROI,2)
    portion = gr_img(i:i+size(ROI,1)-1,j:j+size(ROI,2)-1);
    val(i,j) = corr2(ROI,portion);
    [r,c] = find(val == 1);
    rect = [c r size(ROI,2) size(ROI,1)];
    figure(7),imshow(gr_img),title('Region Segmented')

    if newstats.Centroid(1) < 128
    rem_reg = gr_img:),round(newstats.BoundingBox(1)+60):end);
    rem_reg = gr_img:),1:round(newstats.BoundingBox(1)));
    % figure(8),imshow(rem_reg),title('Remaining Region')
    % pause(0.5)
    % pos = find(all(rem_reg'<3));
    % diff_pos = diff(pos);
    % sep_point = find(diff_pos > 1);
    % rem_reg(pos(sep_point+1)-1:pos(end),:) = [];
    % rem_reg(pos(1):sep_point+1,:) = [];
    rem_reg(217:end,:) = [];
    rem_reg(1:40,:) = [];

    rem_loc = find(any(rem_reg<3));
    if isempty(rem_loc)
    rem_ROI = rem_reg;
    elseif rem_loc(1) == 1
    rem_ROI = rem_reg:),rem_loc(length(rem_loc))+1:end);
    rem_ROI = rem_reg:),1:rem_loc(1)-1);
    % figure(9),imshow(rem_ROI),title('Remaining region to Contour Detection')
    % pause(0.5)

    [ubin c xarr yarr cmat wdt] = test_activecontour('RemR.tif',0,10);
    disp('Optic Disc - Not Spotted')
    % close all

Posted By: PrashanthS
Date Posted: 06-Feb-2018 at 6:48pm
Have you typed "guide" in Matlab?

Posted By: LokeshNash
Date Posted: 06-Feb-2018 at 6:49pm
yes sir.but i need two pushbuttons to upload input and output.also i need two axes in order to show the input,region of segmentation and the output.I am not able to edit the programe in the m file editor

Posted By: Krishna_Sridhar
Date Posted: 06-Feb-2018 at 6:50pm
Dear Lokesh,

mark your code with comments and do sort it with required GUI components. I am pretty much sure you'll do it by your own. MATLAB GUI is not that difficult.
Give it a try or come back with sorted and commented code.

Posted By: skumar
Date Posted: 06-Feb-2018 at 6:51pm
hi can u send me the algorithm of your doing a similar project and in need of the algorithm..



Posted By: Stranger
Date Posted: 06-Feb-2018 at 6:52pm
I've done quite a bit of matlab GUI hacking.... there is too much to relay in a post here. I will give you some hints that I think will help you along.

Guide will create a .fig file and a .m file. The m file holds the code, the fig file hold the graphics objects.

Use guide to create the layout of your GUI. Place a single axes object and two buttons. Use the property editor to name them something identifiable. Save it and switch over to the m file. This file contains a list callbacks that execute on GUI events, such as button presses.

In the GUI opening function, you can handle the initialization. If you want to open the gui with a command such as openGUI('file_to_read'), then this would be where you read the file, do initial processing and plot the image. These parameters are passed in using the varargin struct...if you don't know what that is, look it up.

You will want to pull out the important parts of your script and convert them to functions that perform very specific actions....for instance reading data from a file and converting it into a usable form...or writing data to a file...or applying some filter....or plotting the data, etc. How many pieces you break it into depends on how you reuse those functions and what stuff you need to change. For instance, you could have one function that reads the data and plots it every time you change a setting, or you could have one function to read the data and store it in a variable, then call a second plot function every time a parameter changes.

Once you have your functions written, then decide on the interaction. When a button is pressed, the callback is fired...this function should be populated in the m file already. The handles structure is what allows you to persist data in the figure. For instance, when you read data from a file, you would write it to the handles structure, so later functions can access the data without reloading it. The handles structure also contains the handles to all of the graphic objects, which allow you to edit and modify them directly. For instance, you can grab the current position of the existing axis, and use that to create a second axis object that overlaps the first exactly. Do this in your opening function, and you now have 2 stacked axes. You can specify the axes handles in plot commands like image, imagesc, plot, scatter, etc... so plotting overlays in your plot function are as simple retrieving the axes handles from the handles struct and passing them to your plotting functions. E.G.


notice that imagesc and scatter handle the axes handle differently.

To handle the file IO, look into uigetile and uiputfile. These will open a window that lets you select a file and will return the file name and path (they don't actually do anything to the file). Once you have the path and name, then you can use load, imread, save, imwrite, or whatever you want to actually read/save the file. the fullfile function will help put the path and name together.

Posted By: siva
Date Posted: 06-Feb-2018 at 6:53pm
yeah,good job, yes sir.but i need two pushbuttons to upload input and output.thanks

Posted By: Stranger
Date Posted: 06-Feb-2018 at 6:54pm
i told you how to do that.....

make two buttons. For the 'read' data button, use uigetfile in the call back to let the user select the file. Uigetfile returns the path and file name...use those and imread or load or whatever to read the file, then apply whatever preprocessing you do to it and store it in the handles struct.

for the 'write' data button, use uiputfile in the callback to get the path info for the file to write to. Then format your data however you want it, and use save, imwrite, etc to save the data.

Print Page | Close Window