MATLAB: How to replace certain gray level values in image to find information loss in both

entropyMATLAB

I'm finding information loss in Img1 and its replica Img2 when only a certain gray level values are allowed.
Entropy_Info_Loss=Entropy(Img1)-Entropy(img2);
where img2 must not have gray values other than eg.
only_include=[20, 30, 50].
img2(img1(:)~=only_include)=0;
However my result is all zeros image of img2. Can anyone assist me..

Best Answer

mask = ismember(img1, only_include);
img2 = img1;
img2(~mask) = 0;