How to use LUT in image processing?
17 views (last 30 days)
Show older comments
Hi,
I have two images:
- one binary image which can be used as a mask (BW) and
- a grayscale image (Image).
I'd like to create an array (or a LUT) so that:
For each blob from the binary image, I can put all the corresponding values from the gray scale image.
How do I initialize the LUT? What would be the size of the LUT?
% Read each blob
L = bwlabel(BW);
nbLabels = max(max(L));
for iBlob = 1:nbLabels
% find all coordinates of the current blob
[r, c] = find(L == iBlob);
rc = [r c];
values = Image(r,c); % rc may be Nx2
LUT(r, c) = values;
end
How to use this LUT later by indexing ?
Thank you very much.
0 Comments
Accepted Answer
Image Analyst
on 25 May 2022
Edited: Image Analyst
on 25 May 2022
I'm not sure what you want to do. It sounds like you're describing masking, where you have a binary image of blobs and black background, and you'd like the pixels inside the blob to have the original gray levels, and where the binary image is black you want the masked image to be black. To do that you'd do
maskedImage = grayImage; % Make copy of original image
maskedImage(~BW) = 0; % Erase image where it's black in the binary image.
Alternatively, you can also do it this way, which will work for both gray scale and RGB images:
% Mask image by multiplying each channel by the mask.
maskedRgbImage = rgbImage .* cast(mask, 'like', rgbImage); % R2016b or later. Works for gray scale as well as RGB Color images.
% For R2016a or earlier, mask the image using bsxfun() function to multiply the mask by each channel individually. Works for gray scale as well as RGB Color images.
% maskedRgbImage = bsxfun(@times, rgbImage, cast(mask, 'like', rgbImage)); % R2016a or earlier.
I'm not sure how a lookup table would be involved here.
More Answers (0)
See Also
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!