Questions tagged [run-length-encoding]

Run-length encoding (RLE) is a very simple form of data compression in which runs of data (that is, sequences in which the same data value occurs in many consecutive data elements) are stored as a single data value and count, rather than as the original run.

Run-length encoding is most useful on data that contains many such runs: for example, simple graphic images such as icons, line drawings, and animations. It is not useful with files that don't have many runs as it could greatly increase the file size.

254 questions
7
votes
3 answers

Count consecutive elements in a same length vector

If I have a vector like "a": 0 0 1 1 1 0 0 0 0 1 1 0 0 0 How can I generate a vector of the same length containing the count of consecutive elements, like so: "b": 2 2 3 3 3 4 4 4 4 2 2 3 3 3 I tried rle, but I did not manage to stretch it out…
Cos
  • 1,649
  • 1
  • 27
  • 50
7
votes
4 answers

Incremental sequences with interruptions

I have a dataset with repeating sequences of TRUE that I would like to label based on some conditions - by id, and by the sequence's incremental value. A FALSE breaks the sequence of TRUEs and the first FALSE that breaks any given sequence of TRUE…
iskandarblue
  • 7,208
  • 15
  • 60
  • 130
7
votes
1 answer

Efficiently construct GRanges/IRanges from Rle vector

I have a Run length encoded vector representing some value at every position on the genome, in order. As a toy example suppose I had just one chromosome of length 10, then I would have a vector looking…
7
votes
4 answers

Finding the minimum length RLE

The classical RLE algorithm compresses data by using numbers to represent how many times the character following a number appears in the text at that position. For example: AAABBAAABBCECE => 3A2B3A2B1C1E1C1E However, in the above example, that…
IVlad
  • 43,099
  • 13
  • 111
  • 179
6
votes
3 answers

Series of consecutive numbers (different lengths)

I would appreciate if someone showed me an easy way to do this. Let's say I have a vector in MATLAB like d = [3 2 4 2 2 2 3 5 1 1 2 1 2 2 2 2 2 9 2] I want to find the series of consecutive number "twos" and the lengths of those series. Number twos…
alex
  • 87
  • 1
  • 1
  • 4
6
votes
1 answer

Compression of RGB-D video from a Kinect camera

I need to send video from a Kinect camera through a network. I'm capturing video from the following two Kinect sources: 2D color video (RGB). 32 bits per pixel. 640x480 at 30fps. Depth data (D). 16 bits per pixel representing distance to the…
5
votes
2 answers

Compressing a sinewave table

I have a large array with 1024 entries that have 7 bit values in range(14, 86) This means there are multiple range of indices that have the same value. For example, consider the index range 741 to 795. It maps to 14 consider the index range 721 to…
PoorLuzer
  • 24,466
  • 7
  • 31
  • 35
5
votes
2 answers

Groupby object disappears after list operation

I am trying the run-length encoding problem, and after running a groupby & list operation, my groupby object somehow disappeared. import itertools s = 'AAAABBBCCDAA' for c, group in itertools.groupby(s): print(list(group)) …
Bao Le
  • 98
  • 7
5
votes
4 answers

Grouping of R dataframe by connected values

I didn't find a solution for this common grouping problem in R: This is my original dataset ID State 1 A 2 A 3 B 4 B 5 B 6 A 7 A 8 A 9 C 10 C This should be my grouped resulting dataset State min(ID) max(ID) A 1 …
HansHupe
  • 476
  • 3
  • 13
5
votes
3 answers

Contour of a run-length-coded digital shape

A digital shape is a set of connected pixels in a binary image (a blob). It can be compactly represented by run-length coding, i.e. grouping the pixels in horizontal line segments and storing the starting endpoint coordinates and the lengths.…
user1196549
5
votes
4 answers

Counting runs in columns of a matrix

I have a matrix of 1s and -1s with randomly interspersed 0s: %// create matrix of 1s and -1s hypwayt = randn(10,5); hypwayt(hypwayt > 0) = 1; hypwayt(hypwayt < 0) = -1; %// create numz random indices at which to insert 0s (pairs of indices may …
siegel
  • 819
  • 2
  • 12
  • 24
5
votes
6 answers

Run-length encoding of a given sorted string

Write code for run -length encoding of a given string Sample Input: aaaaaaaaaabcccccc Output: a10bc6 My code: static void Main(string[] args) { string str = "aaaaaaaaaabcccccc"; var qry = (from c in str group c by c into…
Hui Zhao
  • 655
  • 1
  • 10
  • 20
4
votes
1 answer

RLE sequence, setting a value

Say I have an arbitrary RLE Sequence. (For those who don't know, RLE compresses an array like [4 4 4 4 4 6 6 1 1] into [(5,4) (2,6) (2,1)]. First comes the number of a particular integer in a run, then the number itself.) How can I determine an…
user977036
  • 51
  • 2
4
votes
4 answers

Create group number for runs of non-NA values

I have the following dataframe df (dput below): > df id value 1 1 1 2 2 3 3 3 2 4 NA 1 5 NA 3 6 8 4 7 9 2 8 10 1 9 NA 1 10 NA 3 11 15 2 12 16 1 13 NA 3 14 NA 4 15 NA 2 16…
Quinten
  • 35,235
  • 5
  • 20
  • 53
4
votes
3 answers

Extend runs of certain length

I have a 640 x 2500 dataframe with numeric values and several NA values. My goal is to find a minimum of 75 consecutive NA values in each row. For each such run, I want to replace the previous and following 50 cells with NA values too. Here's a…
NickB
  • 103
  • 5
1
2
3
16 17