Switch to unified view

a b/functions/functions_preProc/extractROI.m
1
function [ROI_rz, errorV] = extractROI(im, filename, mask, dirResults, params, plotta, savefile)
2
3
%init
4
errorV = 0;
5
6
%ellipse fit
7
[ix, jy] = find(edge(mask, 'sobel'));
8
ellipse_t = fit_ellipse(ix, jy, im, filename, mask, dirResults, plotta, savefile);
9
minAxis = ellipse_t.short_axis;
10
11
%center
12
%center = [ellipse_t.X0_in, ellipse_t.Y0_in];
13
%center = [mean(ix), mean(jy)];
14
%in ALL-IDB2, center of the image
15
center = [floor(size(im,1)/2), floor(size(im,2)/2)];
16
17
%select
18
radiusSelect = round(minAxis/2 * params.axisScaleFac);
19
centerRound = round(center);
20
try %maybe goes beyond image
21
    ROI = im(centerRound(2) - radiusSelect : centerRound(2) + radiusSelect, centerRound(1) - radiusSelect : centerRound(1) + radiusSelect, :);
22
catch %try
23
    try %try
24
        radiusSelect = round(minAxis/2);
25
        ROI = im(centerRound(2) - radiusSelect : centerRound(2) + radiusSelect, centerRound(1) - radiusSelect : centerRound(1) + radiusSelect, :);
26
    catch %try
27
        ROI_rz = [];
28
        errorV = -1;
29
        return;
30
    end %try
31
end %try
32
33
%resize
34
ROI_rz = imresize(ROI, params.roiSize);
35
36
%display
37
if plotta
38
    fh = figure;
39
    subplot(1,2,1)
40
    imshow(im)
41
    title('Original')
42
    subplot(1,2,2)
43
    imshow(ROI)
44
    title('ROI');
45
    
46
    str = [filename '; ROI extraction'];
47
    
48
    mtit(fh, [filename '; ROI extraction'], 'Interpreter', 'none', 'fontsize', 14, 'color', [1 0 0], 'xoff', .0, 'yoff', .0);
49
    
50
    if savefile
51
        export_fig(gcf, [dirResults str '.jpg']);
52
    end %if save
53
    
54
end %if plotta
55
56
57