Browse Source

업데이트 'step4_extract_image_statistics.m'

Hio-Been Han 6 months ago
parent
commit
cc79bc3be7
1 changed files with 60 additions and 0 deletions
  1. 60 0
      step4_extract_image_statistics.m

+ 60 - 0
step4_extract_image_statistics.m

@@ -122,3 +122,63 @@ for videoIdx = 1:length( video_names )
     csvwrite( csv_filename, xy );
     
 end
+
+
+%% Sample visualization
+csv_files = dir( [ csv_file_directory '*.csv'] );
+for fileIdx = 1:length(csv_files)
+    
+    %% 1. Trace
+    % Get coordinate
+    xy = csvread( [csv_file_directory csv_files( fileIdx ).name] )/448;
+    
+    % Calc speed
+    speed = [0; smooth( sum(abs(diff(xy,2)),1), 5 )];
+    speed = speed/max(speed);
+    outliers = find( speed > (nanmean(speed)+nanstd(speed)*3) );
+    xy(outliers) = nan;
+    
+    % Plot
+    subplot( 2,4, fileIdx ); hold off
+    plt = plot( xy(1,:), xy(2,:), 'k.');
+
+    % Enhance visibility
+    set(gca, 'XDir', 'normal', 'YDir', 'reverse');
+    set(gca, 'XTick', [], 'YTick', [], 'LineWidth', 2, 'Box', 'on', 'FontSize', 15 );
+    axis([0 1 0 1]);
+    title( sprintf( 'Trace (File %1d)', fileIdx ) );
+    
+    %% 2. Histogram
+    % Get coordinate
+    edges = linspace( 0, 1, 100 );
+    [n,xedge,yedge] = hb_histcount2( xy(1,:), xy(2,:), edges, edges );
+    try,n=imgaussfilt(n,1);end
+    
+    % Plot
+    subplot( 2,4, 4+fileIdx ); hold off
+    imagesc( xedge, yedge, log(n)' );
+
+    % Enhance visibility
+    set(gca, 'XDir', 'normal', 'YDir', 'reverse');
+    set(gca, 'XTick', [], 'YTick', [], 'LineWidth', 2, 'Box', 'on', 'FontSize', 15 );
+    title( sprintf( 'Occupancy (File %1d)', fileIdx ) );
+    axis([0 1 0 1]);
+    colormap hot;
+end
+
+% Subfunction
+function [n,xedge,yedge,idx] = hb_histcount2(X, Y, xedge, yedge)
+nbin = [length(xedge)-1, length(yedge)-1];
+for binIdx_x = 1:nbin(1)
+    xIdx = (X>xedge(binIdx_x)) .* (X<=xedge(binIdx_x+1));
+    for binIdx_y = 1:nbin(2)
+        yIdx = (Y>xedge(binIdx_y)) .* (Y<=xedge(binIdx_y+1));
+        jointIdx = find( xIdx .* yIdx );
+        n( binIdx_x, binIdx_y ) = length(jointIdx);
+        idx{binIdx_x, binIdx_y} = jointIdx;
+    end
+end
+end
+
+
+