Skip to main content
  • Home
  • Development
  • Documentation
  • Donate
  • Operational login
  • Browse the archive

swh logo
SoftwareHeritage
Software
Heritage
Archive
Features
  • Search

  • Downloads

  • Save code now

  • Add forge now

  • Help

Revision 1dc429fc0da4cc5ff4f62617760447613f85980b authored by vbhandawat on 01 February 2021, 13:54:09 UTC, committed by GitHub on 01 February 2021, 13:54:09 UTC
Add files via upload
1 parent 17f20a6
  • Files
  • Changes
  • 345c390
  • /
  • Tracking
  • /
  • trueBackground.m
Raw File Download
Permalinks

To reference or cite the objects present in the Software Heritage archive, permalinks based on SoftWare Hash IDentifiers (SWHIDs) must be used.
Select below a type of object currently browsed in order to display its associated SWHID and permalink.

  • revision
  • directory
  • content
revision badge
swh:1:rev:1dc429fc0da4cc5ff4f62617760447613f85980b
directory badge Iframe embedding
swh:1:dir:d95c030c609a587149c58f34f4d09a16b4a9bdc6
content badge Iframe embedding
swh:1:cnt:fc1cd108a356e8e91008cbc198842a2e1f2d513f
Citations

This interface enables to generate software citations, provided that the root directory of browsed objects contains a citation.cff or codemeta.json file.
Select below a type of object currently browsed in order to generate citations for them.

  • revision
  • directory
  • content
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
trueBackground.m
%This code returns a reasonably good background estimation of a video.
%@Chanwoo Chun <cc2465@cornell.edu>

function background = trueBackground(frames)
tframes=size(frames,3);

for column = 1:size(frames,2)
    %A single column of a frame is chosen. Now, from the start to the end
    %of the video, take a sum of the pixel intensity values of the column
    %and then square it.
    for i = 1:tframes
        columnBrSum(i) = sum(frames(:,column,i))^2;
    end
    %Imagin you are plotting columnBrSum array (x-index, y-element
    %value).
    %If some object passed through this column at some point, the array
    %columnBrSum will have some elements whose values are higher than
    %others.
    %Therefore, when columnBrSum is plotted, there would be a baseline
    %where nothing happens. We want to identify the index values of the
    %baseline, and take average of the columnes of that index (frame)
    %values. Doing this for every column will give us a background.
    
    
    %Again, imagine the columnBrSum plot. Now, we add a horizontal line
    %that crosses on top of the columnBrSum plot. This line starts from the
    %minimum value of columnBrSum and slides up a little by a predefined
    %amount (this value may need to be changed depending on a
    %characteristic of a video). In the for loop below, we are essentially
    %counting the number of intersections between the line and columnBrSum
    %plot. 
    lowMinimum = min(columnBrSum);
    maxPopNum = 1;
    for scan = lowMinimum:0.05e7:lowMinimum+5e7
        population = false(tframes,1);
        for i = 2:tframes
            if (columnBrSum(i)>=scan && columnBrSum(i-1)<=scan)||...
                    (columnBrSum(i)<=scan && columnBrSum(i-1)>=scan)
                population(i-1:i) = true;
            end
        end

        popNum = size(find(population),1);

        if popNum > maxPopNum
            maxPop = population;
            maxPopNum = popNum;
        end
    end

    
    %Now the following block determines when the object appeared and
    %disappeared. We are going to mask out the portion where the object is
    %detected, and then take average of the columns.
    %However, other simpler methods may work. For example, we can skip to
    %the line where variable multiBack is defined, and then set multiBack
    %equal to population <multiBack=population;>. For this, the below 
    %for-loop can be commented out.
    falseCount = 0;
    maxCount = 0;
    for i = 1:tframes   
        if maxPop(i)==false
            falseCount = falseCount+1;
            if i~=tframes
                if maxPop(i+1)==true
                   if  falseCount > maxCount
                       maxCount = falseCount;
                       gone = i;
                       appear = gone-maxCount;
                   end
                   falseCount = 0;
                end
            else
                if  falseCount > maxCount
                       maxCount = falseCount;
                       gone = i;
                       appear = gone-maxCount;
                end
            end
        end
    end
    
    if appear == 0
       appear = 1;
    end

    mask = true(tframes,1);
    mask(appear:gone) = false;

    multiBack = squeeze(frames(:,column,mask));

    avgBackC(:,column) = mean(multiBack,2);
    
    appear = 0;
    gone = 0;
end

background = uint8(255*mat2gray(avgBackC));
The diff you're trying to view is too large. Only the first 1000 changed files have been loaded.
Showing with 0 additions and 0 deletions (0 / 0 diffs computed)
swh spinner

Computing file changes ...

Software Heritage — Copyright (C) 2015–2025, The Software Heritage developers. License: GNU AGPLv3+.
The source code of Software Heritage itself is available on our development forge.
The source code files archived by Software Heritage are available under their own copyright and licenses.
Terms of use: Archive access, API— Contact— JavaScript license information— Web API

back to top