code folders:
output folder:
How to run it?
main_ITSBNImageSegm.m
This is the main function to run ITSBN. The code calls other functions necessary for image segmentation. Normally there are 2 modes to run the code:
All the processed data (e.g., superpixels, feature vectors, ITSBN tree) can be stored for future experiments in case that the environment of superpixel, tree is needed to be controlled. The code does the following jobs:
The functions in the folder toolbox_ITSBN will be explained here.
fn_SuperpixelMori2.m
function [] = fn_SuperpixelMori2(imagename, imageext, N_l4, N_l3, N_l2, N_l1)
This is the function to make superpixels in each level. The level here is fixed to 4. The output of the file is cell array img_label_hier whose format are
each column:
each row:
For instance, the matrix looks like this.
The cell array img_label_hier is stored in the file imagename_img_label_hier.mat
fn_makeTreeFromLabel.m
[] = fn_makeTreeFromLabel(imagename)
The code take as an input the matrix img_label_hier, then output the followings:
All the outputs from the code are stored in imagename_package.mat.
fn_imageFeatureExtraction2.m
[] = fn_imageFeatureExtraction2(imagename, imageext)
All the feature vectors are calculated from this code. The code take the imagename_package.mat as input and store feature vectors in the file imagename_feature.mat. The output matrices are
This code works as follows:
Note that we have the evidence only in the level H^0 only. In the next version, we will make multiscale evidence.
fn_imgSegmentationGMM.m
function [I_label, I_post] = fn_imgSegmentationGMM(imagename, imageext, C, W)
The algorithm uses GMM to segment the raw data in pixel level, and the features are Lab and location x, y of the image.
fn_ITSBNImageSegm2.m
[] = fn_ITSBNImageSegm2(filename_input,...
imagename, imageext,...
C,...
iteration_max,...
exp_number,...
cpt_spread_factor,...
added_diag_cpt,...
epsilon_F)
This code, regarded as the core of the ITSBN, takes as input the image and all the features extracted from the previous process, then output the segmentation results in imagename_ITSBN_segm_result.mat. The results are composed of
Since we are using the BNET MATLAB toolbox, we have some tricks to combine the toolbox with our method seamlessly. The code is explained in detail as follows:
fn_pseudoDiag.m
a = fn_pseudoDiag(r,c)
The functions in the folder toolbox_visualization will be explained here.
fn_segment2boundary.m
detected_contour = fn_segment2boundary(segm_output, figure_toggle)
This code convert a segmentation output into a boundary image by differentiating the segments. The function will show the image when figure_toggle = 'on', and otherwise when 'off'.
fn_overlayGTORGBND.m
Iorg_gt_boundary = fn_overlayGTORGBND(Igray, Igt, Ibnd);
Overlay the original image, the groundtruth and the boundary on the same image. The original image can be either rgb or gray scale.
fn_visualizeITSBNgraph.m
function [] = fn_visualizeITSBNgraph(imagename, imageext)
The code calculate the centroid of each superpixel and show the boundaries of superpixels 2 levels at a time. There is no limitations in the number of the level L in this code.
fn_stackSuperpixelFeatureImage.m
[I_show] = fn_stackSuperpixelFeatureImage(index_field, feature_index, feature, display_feature)
Rearrange the feature vector matrix in cube
% #########################################################################
%
% OUTPUT:
% This code will create a stack of feature image Nrow x Ncol x feat_D. And
% if display_feature is determined, the functin will show figure too.
%
% INPUT:
% index_field = Nrow x Ncol matrix, each entry contains superpixel index in which the pixel resides.
% Also, each entry represents a pixel on the actual image.
% feature_index = a column vector containing superpixel indices in
% ascending order.
% feature = each row of this matrix means the feature vector for that
% particular superpixel.
% display_option = The feature that you want to plot, so the maximum length
% of this row vector is 3 since we have only R G B. if this is not determined,
% the function will not plot anything.
% ############################ EXAMPLE ####################################
% [I_show] = fn_stackSuperpixelFeatureImage(evidence_label, Y_index, Y);
% This option will just produce the feature stack cube, but not display the
% figure.
% [I_show] = fn_stackSuperpixelFeatureImage(evidence_label, Y_index, Y, [1 3 5]);
% This option also display the feature image too.
% #########################################################################
The functions in the folder toolbox_ITSBN will be explained here.
The functions in the folder toolbox_ITSBN will be explained here.