Fast way to map pixel values in a image to different values
4 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
回答(1 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!