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

4 Ansichten (letzte 30 Tage)
Amandeep Gautam
Amandeep Gautam am 24 Nov. 2016
Beantwortet: Image Analyst am 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.

Antworten (1)

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

Kategorien

Mehr zu Images finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by