Create a LUT Table by Euclidean Distance
Show older comments
Hello,
I have a list of N vectors in 3D space (Points in RGB color space). We'll call that our Dictionary.
The whole data M is in 3D Space ({0, 1, ..., 255} x {0, 1, ..., 255} x {0, 1, ..., 255}).
I want to create a LUT which works in the following way, each point in the Space will be mapped to the point dictionary according to Euclidean Distance.
This can be also seen as a quantization process of an image. I want to create a LUT Table s.t. is pixel will be quantized into a value of the Code Book which is the most similar to it in the L2 / Euclidean sense.
How can I do it in a vectorized, efficient manner?
This is a sample code I created using loops:
function [ mRgbLut ] = CreateRgbLUT( mCodeBook )
mRgbLut = zeros(256, 256, 256);
numLevels = size(mCodeBook, 1);
for iRValue = 0:255
redIdx = iRValue + 1;
for jGValue = 0:255
grennIdx = jGValue + 1;
for kBValue = 0:255
blueIdx = kBValue + 1;
vCurrColor = [iRValue, jGValue, kBValue];
vRgbDistance = sum(((repmat(vCurrColor, [numLevels, 1]) - mCodeBook) .^ 2), 2);
[minRgbDist, codeBookIdx] = min(vRgbDistance);
mRgbLut(redIdx, grennIdx, blueIdx) = sub2ind([256, 256, 256], mCodeBook(codeBookIdx, 1), mCodeBook(codeBookIdx, 2), mCodeBook(codeBookIdx, 3));
end
end
end
end
Thank You.
Accepted Answer
More Answers (0)
Categories
Find more on Image Processing Toolbox in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!