Do any #rstats gurus happen to know about a package function that does the 2D equivalent of run length encoding?

The idea is for a matrix like the following...

> m <- matrix(c(1,1,2,1,1,2,2,2,1), 3, 3)
> m
[,1] [,2] [,3]
[1,] 1 1 2
[2,] 1 1 2
[3,] 2 2 1

...find (the positions of) rectangles with the same value. For example the first 'run' is m[1:2, 1:2] in this case, the second m[1:2, 3], third m[3, 1:2] and last m[3, 3].

@teunbrand I'll probably spend all day thinking about this!

#NerdSniped #RStats

@teunbrand First draft.

Notes:
* There's an interesting choice to be made when multiple candidates match
* Locally optimal/greedy matching probably gives globally sub-optimal final result
* Feels like there should a 2d divide/conquer method.
* Also feels like there should be a 2d growth+simulated annealing that would producing something nice
* quadtrees / binary space partitioning methods?

Do you have interesting test cases to try this on?

#RStats #NerdSniped

@coolbutuseless @teunbrand I strongly suspect I'll want to use whatever you come up with if I ever finish https://jonthegeek.github.io/tableguess/ (which will likely become {maitre} if I ever finish it, since it finds a table for you)
Find Tables in Plain Text

The goal of tableguess is to automatically extract table-like objects out of plain text files.

@jonthegeek @coolbutuseless @teunbrand

Here is an approach to do #2D #RLE applied to the processing of #ECG images: https://link.springer.com/chapter/10.1007/978-981-13-5802-9_86, and also there is a 3D RLE approach for volumetric medical image data: https://www.tandfonline.com/doi/abs/10.1080/13682199.2019.1565695
In my previous #Bioinformatics life, RLE was used, there is rle2() for the #Bio3D package which uses indices (http://thegrantlab.org/bio3d/reference/rle2.html).
Also, there is an improvement of RLE with a bit of Huffman encoding thrown in: https://arxiv.org/abs/2101.05329

An Image Processing Approach for Compression of ECG Signals Based on 2D RLE and SPIHT

This paper proposes an image processing approach for compression of ECG signals based on 2D compression standards. This will explore both inter-beat and intra-beat redundancies that exist in the ECG signal leading to higher compression ratio (CR) as compared to 1D...

SpringerLink

@jonthegeek @coolbutuseless @teunbrand

And another article on the application of 2D RLE to general image compression, mixing RLE and Huffman for the 2D case: https://join.if.uinsgd.ac.id/index.php/join/article/view/330 -- this one goes row-wise and then column-wise.

The BACIC technique referred in this paper is described in: https://pubmed.ncbi.nlm.nih.gov/18249657/

Lossless Text Image Compression using Two Dimensional Run Length Encoding | Jurnal Online Informatika

@jmcastagnetto @jonthegeek @coolbutuseless Thanks for the article links! I really need the position information rather than good compression (and need to stay in R), so these seem like really nice solutions for related problems.