GUI for matlab code

Discussion in 'Programmer's Corner' started by theertham, Jun 11, 2012.

  1. theertham

    Thread Starter New Member

    Apr 28, 2012
    26
    0
    hi
    can anyone help me to develop GUI(graphic user interface) for my matlab code for retinal image analysis.my code is used to detect optic disc and exudate in retinal images using contour techniques

    clc
    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')
    pause(0.2)
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    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')
    pause(0.2)
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    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);
    end
    end
    else
    stats = regionprops(L,'basic');
    if stats.Centroid(2) < 100 || stats.Centroid(2) > 150
    % disp('3:Optic Disc - Not Spotted')
    newstats = [];
    else
    newstats = stats;
    end
    end
    if ~isempty(newstats)
    if newstats.BoundingBox(3) < 50
    newstats.BoundingBox(1) = newstats.BoundingBox(1) - ...
    (50 - newstats.BoundingBox(3))/2;
    newstats.BoundingBox(3) = 50;
    end
    if newstats.BoundingBox(4) < 50
    newstats.BoundingBox(2) = newstats.BoundingBox(2) - ...
    (50 - newstats.BoundingBox(4))/2;
    newstats.BoundingBox(4) = 50;
    end
    if newstats.BoundingBox(3) > 100
    newstats.BoundingBox(3) = 100;
    end
    if newstats.BoundingBox(4) > 140
    newstats.BoundingBox(2) = newstats.BoundingBox(2) + 20;
    newstats.BoundingBox(4) = 110;
    end

    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);
    else
    ROI = region:),1:uiloc(1)-1);
    end
    % figure(5),imshow(ROI),title('Input to Contour detection')
    % pause(0.5)
    imwrite(ROI,'ODisc.tif')
    [ubin c xarr yarr cmat wdt] = test_activecontour('ODisc.tif',0,6);
    pause(1)

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %% 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);
    end
    end
    [r,c] = find(val == 1);
    rect = [c r size(ROI,2) size(ROI,1)];
    figure(7),imshow(gr_img),title('Region Segmented')
    rectangle('Position',rect,'EdgeColor','g')
    pause(1)
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

    if newstats.Centroid(1) < 128
    rem_reg = gr_img:),round(newstats.BoundingBox(1)+60):end);
    else
    rem_reg = gr_img:),1:round(newstats.BoundingBox(1)));
    end
    % 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);
    else
    rem_ROI = rem_reg:),1:rem_loc(1)-1);
    end
    % figure(9),imshow(rem_ROI),title('Remaining region to Contour Detection')
    % pause(0.5)

    imwrite(rem_ROI,'RemR.tif')
    [ubin c xarr yarr cmat wdt] = test_activecontour('RemR.tif',0,10);
    pause(2)
    else
    disp('Optic Disc - Not Spotted')
    end
    % close all
    end
     
    • 75.jpg
      75.jpg
      File size:
      60.2 KB
      Views:
      96
    Last edited: Jun 11, 2012
  2. MrChips

    Moderator

    Oct 2, 2009
    12,421
    3,357
    Have you typed "guide" in Matlab?
     
  3. theertham

    Thread Starter New Member

    Apr 28, 2012
    26
    0
    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
     
  4. kitto326

    New Member

    Aug 21, 2009
    2
    0
    Dear theertham,

    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.
     
  5. umasathyananth

    New Member

    Oct 4, 2012
    1
    0
    hi can u send me the algorithm of your code..im doing a similar project and in need of the algorithm..

    thanks

    uma
     
  6. vortmax

    Member

    Oct 10, 2012
    103
    18
    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.

    Plot_callback(handles)
    imagesc(handles.data,'Parent',handles.lowerAxes');
    scatter(handles.topAxes,handles.POI:),1),handles.POI:),2));
    end

    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.
     
  7. goprofishs

    New Member

    Dec 17, 2012
    3
    0
    yeah,good job, yes sir.but i need two pushbuttons to upload input and output.thanks[​IMG]
     
  8. vortmax

    Member

    Oct 10, 2012
    103
    18
    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.
     
Loading...