#!/usr/bin/octave -qf
% -*- mode: octave; coding: utf-8 -*-

warning ("off");
arg_list = argv ();


%%%
%%% Pkg
%%%

pkg load image


%%%%
%%%% Functions and images search path
%%%%

addpath("/usr/lpdi/projects/octave/ocom")
addpath("/usr/lpdi/projects/octave/ocom/tests")


%%%
%%% arg_list processing
%%%

im_path = arg_list{1};
im_name = arg_list{2};
im_type = arg_list{3};

im_filename = [im_path, '/', im_name, '.', im_type];
I = imread(im_filename);
I = logical(I);
I = bwlabel(I, 4);
stats = regionprops(I, 'Area', 'BoundingBox', 'Image');

i = 1;
stats(i).BoundingBox;

p(i, 1 : 4) = stats(i).BoundingBox;
p(i, : ) = round(p(i, : ));

x1 = p(i, 1);
x2 = p(i, 1) + p(i, 3) - 1;
y1 = p(i, 2);
y2 = p(i, 2) + p(i, 4) - 1;

sm = I(x1 : x2, y1 : y2, :);

imshow(I);
figure, imshow(sm)

%% using 3.6 - 2.0.0-3 values
x1 =  1;
x2 =  39;
y1 =  37;
y2 =  100;
sm = I(x1 : x2, y1 : y2, :);
figure, imshow(sm)

keyboard
