Assign values from an matrix to another by using row and column indexes -- array exceeds maximum array size preference

3 visualizaciones (últimos 30 días)
Hi
So I have an image (345*345 matrix), and I did this
[row, column] = find(image == 1);
i.e., to get the row and column indexes for all pixel values that is 1.
This is a binary image, so a lot if pixles have value 1. So the 'row' and 'column' each returns a 57033*1 size big array.
Now I want to assign a different values from another matrix to those pixel values that originally were 1. And they should be 1-1 matching from the two images using those indexes, something like below:
image(row,column) = image_new(row, column);
But then matlab returned an error:
Requested 57033x57033 (24.2GB) array exceeds maximum array size preference (16.0GB). This might cause MATLAB to become unresponsive.
Just wondering is there still a way to do what I propose to do. i.e., assign the values that were 1 from a new matrix in the same pixel positions? (you can think that the new matrix was like a foreground of the image to fill into the original binary image.)
Thanks in advance!

Respuestas (1)

Image Analyst
Image Analyst el 24 de Nov. de 2023
You can just use the logical image. Don't use find or rows or columns at all. Simply do
mask = image1 == 1; % Logical image.
image1(mask) = image_new(mask)
  1 comentario
Dyuman Joshi
Dyuman Joshi el 24 de Nov. de 2023
Logical values only take 1 byte per element, whereas double values take 8 byte per element. So the total memory costs will be cut by 7/8th
Not only that, logical indexing is much more faster than find().

Iniciar sesión para comentar.

Categorías

Más información sobre Read, Write, and Modify Image en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by