R how to stack image from their matrix value

akhetos

I got many matrix of size 300*300, which are saved in a list, named L. This is binary matrix, i only have 0 and 1 values. I plot image from those matrix (for exemple with c.img).

What is the best way to create a stack of those matrix? I want to create a new matrix, and or the pixel at the (i,j) position, i want to look in all my matrix saved in L, and if one or more matrix have a 1 at this position, then the (i,j) pixel in my new matrix will have value 1, else 0.

Here a pseudo code to help you understand my goal

L <- list(rep(matrix(0 or 1,300,300),n)   
new_matrix<-matrix(0,300,300)

new_matrix[i,j]<- max(L[i,j])

but this code doesnt work because data is a list. I'm prety sure sure i can achieve this task using 3 loop (i,j,n), but because i got many matrix that'll take too long and i'm looking for a faster solution.

Clemsang

You can use :

matrix(as.numeric(Reduce(`+`, data) > 0), 300, 300)

Sum all matrix then convert values greater than 0 to 1 with as.numeric.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to correctly write a raster image (tif) from a value matrix with python

how to stack groups of columns into a new matrix in r?

How to find value from matrix

how to convert a JPEG to an image matrix in R

How to convert times series raster stack to matrix or large list in r?

How to get the RGB matrix from an image?

How to detect edges from image matrix

How to create a color image from matrix?

how to create an image from matrix of colours in swift?

How to remove actions from the value stack?

How to update matrix value in R based on comparison of two matrix?

how to change value of matrix with for loop using another matrix in r?

How to find one value from a matrix

How to stack elements of a list (dataframes or vectors) by rows inside a matrix, including the names of the columns inside the matrix in R?

get value from matrix that have same value in other column in R

How to generate an individual adjacency matrix from a group adjacency matrix, in r

How to remove column names from a matrix in R?

how to read a matrix from text file in R

How to write out from a matrix in R?

How R subtracts a matrix from an integer

How to prevent matrix from becoming list in R?

How to randomly pick a % of observations from a matrix in R?

How to get a specific column from a matrix in r?

How to extracting consecutive columns from a matrix in R?

How to select rows from a matrix in. R

How to serve image from my server with a MERN stack

Select n row have highest combined value from a matrix in R

Deleting the minimum value recursively from a matrix using a loop in R

R-get the position of max value in a vector from a matrix