Fast way to map pixel values in a image to different values

4 views (last 30 days)
I have a image (.tif) in which each pixel takes a value from numbers in keySet. I have to map them to a different value and following is what I did.
keySet = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 254, 255};
%converting to 1-based indexing and creating a map.
valueSet = {1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 2, 2, 2, 4, 5};
tranformMap = containers.Map(keySet,valueSet);
image = readFile(filePath) %reads a .tif file.
for key = keys(tranformMap)
processedImage(image == key{1}) = tranformMap(key{1});
end
Although it works, I was wondering if there was a faster way to do it.

Answers (1)

Image Analyst
Image Analyst on 24 Nov 2016
Yes there is. You can use the "intlut()" function.

Categories

Find more on Images 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!