intlut() alternative for LUT consisting of doubles

5 次查看(过去 30 天)
Is there a fast alterative to intlut() accepting an array of doubles as LUT?
Problem is, I want to convert grayscale values (uint8) of an image using a LUT consisting of 256 doubles.
Example:
lut = (1:256)+0.1; % upshift by 0.1
A = uint8(randi(256,50));
% current approach
lutMat = repmat(reshape(lut, 1, 1, numel(lut)), ...
size(A));
idx = sub2ind( ...
size(lutMat), ...
repmat((1:size(A, 1))', 1, size(A, 2)), ...
repmat((1:size(A, 2)) , size(A, 1), 1), ...
double(A));
B = lutMat(idx);
The above code works fine, but takes a lot of time and needs too much memory
  3 个评论
Stefan
Stefan 2012-8-20
I forgot to add the line
lut = repmat(reshape(lut, 1, 1, numel(lut)), ...
size(A));
just after
% current approach
I changed the code in the original question, accordingly.
Image Analyst
Image Analyst 2012-8-20
You're still having the problem? Didn't my code do what you want?

请先登录,再进行评论。

回答(2 个)

Jan
Jan 2012-8-18
I'm not sure if I understand the question. Does this help:
B = lut(A);

Image Analyst
Image Analyst 2012-8-18
编辑:Image Analyst 2012-8-18
If you're just adding a constant value to the lut-transformed values, like 0.1, you can just do this:
lut = uint8(1:256); % upshift by 0.1
A = uint8(randi(256,50));
B = double(intlut(A, lut)) + 0.1;
If it's not some constant added value, then you can do it like this:
lut = 1000 * rand(256, 1); % A Random reassignment between 0 and 1000.
A = uint8(randi(256,50));
B2 = zeros(size(A), class(lut));
for inputValue = uint8(0) : uint8(255)
indexes = (A == inputValue);
B2(indexes) = lut(inputValue + 1);
end

Community Treasure Hunt

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

Start Hunting!

Translated by