intlut() alternative for LUT consisting of doubles

조회 수: 5 (최근 30일)
Stefan
Stefan 2012년 8월 15일
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