I have a large matrix with pixel values ranging from 0 to 255 and I would like to assign specific values (map) from a txt file (table).
I have looked at other similar questions on this forum but they were focused on replacing a couple of values with "if" conditions which doesn't apply to my case since i have a large matrix.
Here is an example:
Thanks
m = [1 22 33;44 55 66;77 188 255] % pixel default value
m = 3×3
1 22 33 44 55 66 77 188 255
values = [1 1;22 4;33 9;44 35;55 48;66 90;77 99;188 200;255 300] % txt file
values = 9×2
1 1 22 4 33 9 44 35 55 48 66 90 77 99 188 200 255 300
M = [1 4 9; 35 48 90; 99 200 300] % expected result
M = 3×3
1 4 9 35 48 90 99 200 300

 채택된 답변

Stephen23
Stephen23 2022년 2월 18일

0 개 추천

m = [1,22,33;44,55,66;77,188,255] % pixel default value
m = 3×3
1 22 33 44 55 66 77 188 255
v = [1,1;22,4;33,9;44,35;55,48;66,90;77,99;188,200;255,300] % txt file
v = 9×2
1 1 22 4 33 9 44 35 55 48 66 90 77 99 188 200 255 300
[X,Y] = ismember(m,v(:,1));
m(X) = v(Y(X),2)
m = 3×3
1 4 9 35 48 90 99 200 300
Compare against your expected output:
M = [1 4 9; 35 48 90; 99 200 300] % expected result
M = 3×3
1 4 9 35 48 90 99 200 300

추가 답변 (1개)

Image Analyst
Image Analyst 2022년 2월 18일

0 개 추천

Use the function made for this kind of operation : intlut().
Not sure how many thousands or millions of rows your large matrix is but it should work. If your matrix is too huge, like many gigabytes and billions of pixels, then you're going to have problems anyway, regardless of this function.

카테고리

도움말 센터File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

태그

질문:

2022년 2월 18일

댓글:

2022년 2월 20일

Community Treasure Hunt

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

Start Hunting!

Translated by