Replacing all occurrences of a specific value in a matrix with another value
3 次查看(过去 30 天)
显示 更早的评论
Hi,
Context: I am looking to equalize an image without using histeq. The process requires me to work with large matrices.
Problem: I have two matrices - one that is 291x240 (named im2) and another that is 1x256 (named im3). I want to build a for loop (or use anything else - it is not necessary I use a for loop) that replaces all occurances of a certain value in the im2 matrix (lets call the value n) with the value contained in the nth index of im3.
Given: the values contained in im2 and im3 are between 0-256
So far I have the following loop but it gives me weird results:
for n=1:256
im2(im2==n) = im3(n);
end
An example of the result: there are multiple occurances of 107 in im2; in im3, the 107th index contains 134. Thus, if that for loop worked as I understand it, all occurances of 107 in im2 would become 134, and the loop would loop through to do the same thing for n=1-256.
But instead, the occurances of 107 in im2 are changed to 255 and other numbers to other unexpected values.
Any help is appreciated, thank you.
I surfed the web for similar questions and implemented a number of them, but, I did not get the result I need.
0 个评论
采纳的回答
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!