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
2
votes
3 answers

Group index vector from vector with nummer of elements in group

I want to create a vector containing the group identifier for each element from a vector containing the number of elements in each group. Example: E = [2 3 4]' I am looking for a vector as follows: I = [1 1 2 2 2 3 3 3 3] I found one solution…
2
votes
1 answer

Tiling a vector in a unique way MATLAB

Consider A = [ 200000 x 1] vector. I have another vector idx = [200000x1]. I would like to tile A such that every ith element of A is tiled idx(i) times. Eg: A idx output 2 2 2 3 1 2 4 3 3 5 1 4 . . 4 . . 4 . . …
enigmae
  • 349
  • 2
  • 10
2
votes
5 answers

Given a table of data and number of occurrences, can I create the underlying dataset?

I have a 2-column matrix that describes a piece of data, and the number of times that data occurred within a set: A = [1 6 2 2 3 8 …
Dang Khoa
  • 5,693
  • 8
  • 51
  • 80
1
vote
1 answer

Runlength encoded mask is not as same as decoded mask

I'm dealing with a task of doing semantic segmentation on Severstal steel anomaly detection, These are the encoding and decoding functions. def mask_to_rle(mask): """ params: mask - numpy array returns: run-length encoding string (pairs…
1
vote
0 answers

JPEG Specification Questions: Walking through my current understanding to hopefully find what is wrong

I want to make a JPEG where for each of the 3 components (Y, Cb, Cr), you encode a 8x8 block one after another, and then move to the next 8x8 block in the image. E.X. A 16x16 image exists. write header (is there anything special I need to mark? I…
Light916
  • 11
  • 1
1
vote
4 answers

expand a string in JavaScript to display letter and how many times that letter appears

Write a function that accepts a string where letters are grouped together and returns new string with each letter followed by a count of the number of times it appears. example : ('aeebbccd') should produce // 'a1e2b2c2d1' function strExpand(str)…
1
vote
4 answers

How to create an Run Length decoder in python?

I need the decoder to take input like [3, 15, 6, 4] and output [15, 15, 15, 4, 4, 4, 4, 4, 4] I already have an encoder that works perfectly, but I am unsure how I would go about reversing the process.
1
vote
1 answer

Run Length Decoding

I have a function for run length decoding in Python. It is working with single digit numbers, but if my number is above 9, it doesn't work. As you can see in my code, I want to print c 11 times, but it only prints it one time. How can I fix it ? I…
Itay
  • 11
  • 2
1
vote
2 answers

Recursion error at my encode function from “99 questions in Haskell”

The problem is: “Run-length encoding of a list. Use the result of problem P09 to implement the so-called run-length encoding data compression method. Consecutive duplicates of elements are encoded as lists (N E) where N is the number of duplicates…
1
vote
2 answers

Python: how to replace a substring with a number of its occurences?

Let's say I have a string presented in the following fashion: st = 'abbbccccaaaAAbccc' The task is to encode it so that single characters are followed by a number of their occurences: st = 'a1b3c4a3A2b1c3' I know one possible solution but it's…
Ramiil
  • 59
  • 8
1
vote
0 answers

How to change the input in RLE to bytes in Python 3?

I'm trying to change the RLE compress algorithm in python 3. I want the input to be bytes instead of string. The code works with string but it does not compress bytes. Here is the code: def encode(data) -> bytes: encoding = '' prev_byte =…
1
vote
2 answers

Run-length encoding in java

How to print out the number of a specific digit along with the digit itself in form "nxw." n is the frequency of the number, w is the number itself. So, for example, if the user's input was 1 1 1. The output would be 3x1. If the user's input was 1 1…
Ihab98
  • 19
  • 6
1
vote
2 answers

Implementation of the PackBits algorithm

I want to implement the PackBits algorithm. The background is that I am writing some code for an ONVIF camera. I want to compress a pattern/string of 1's and 0's with PackBits, and I also want to decode an existing packed string. JavaScript has my…
Ron
  • 51
  • 3
1
vote
3 answers

Any easier to read run-length Encoding in Swift?

Can anyone write run-length encoding code in swift that is easier to read than the one below or at least explains the one i got from rosettecode.org ? Here is the input& output and the code // "WWWBWW" -> [(3, W), (1, B), (2, W)] func encode(input:…
Ramy Wadia
  • 45
  • 6
1
vote
1 answer

Need help with logic on a weird loop

I'm trying to make a loop that will recurse through an array of bytes and compare them to the next one in the array (presumably using a for loop to iterate through each entry). If the two are the same I need it to increment an int variable and then…
Grimbly
  • 194
  • 8