Assign values from an matrix to another by using row and column indexes -- array exceeds maximum array size preference
조회 수: 4 (최근 30일)
이전 댓글 표시
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!
댓글 수: 0
답변 (1개)
Image Analyst
2023년 11월 24일
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
Dyuman Joshi
2023년 11월 24일
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().
참고 항목
카테고리
Help Center 및 File Exchange에서 Read, Write, and Modify Image에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!