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

조회 수: 4 (최근 30일)
Amandeep Gautam
Amandeep Gautam 2016년 11월 24일
답변: Image Analyst 2016년 11월 24일
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.

답변 (1개)

Image Analyst
Image Analyst 2016년 11월 24일
Yes there is. You can use the "intlut()" function.

카테고리

Help CenterFile Exchange에서 Images에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by