Replacing all occurrences of a specific value in a matrix with another value
4 views (last 30 days)
Show older comments
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 Comments
Accepted Answer
More Answers (0)
See Also
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!