How to use LUT in image processing?
조회 수: 17 (최근 30일)
이전 댓글 표시
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
채택된 답변
Image Analyst
2022년 5월 25일
편집: Image Analyst
2022년 5월 25일
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.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!