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

4 vues (au cours des 30 derniers jours)
Amandeep Gautam
Amandeep Gautam le 24 Nov 2016
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.

Réponses (1)

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

Catégories

En savoir plus sur Images dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by