intlut() alternative for LUT consisting of doubles
Show older comments
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 Comments
Jan
on 18 Aug 2012
When I run your code, I get an error:
??? Error using ==> sub2ind at 58
Out of range subscript.
Stefan
on 20 Aug 2012
Image Analyst
on 20 Aug 2012
You're still having the problem? Didn't my code do what you want?
Answers (2)
Jan
on 18 Aug 2012
I'm not sure if I understand the question. Does this help:
B = lut(A);
Image Analyst
on 18 Aug 2012
Edited: Image Analyst
on 18 Aug 2012
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
Categories
Find more on Contrast Adjustment 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!