How to use LUT in image processing?

30 visualizaciones (últimos 30 días)
Maia2022 el 25 de Mayo de 2022
Comentada: Maia2022 el 26 de Mayo de 2022
I have two images:
  1. one binary image which can be used as a mask (BW) and
  2. 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;
How to use this LUT later by indexing ?
Thank you very much.

Respuesta aceptada

Image Analyst
Image Analyst el 25 de Mayo de 2022
Editada: Image Analyst el 25 de Mayo de 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.

Más respuestas (0)


Más información sobre Image Segmentation and Analysis en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by