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

1 次查看(过去 30 天)
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..

采纳的回答

Walter Roberson
Walter Roberson 2016-4-2
mask = ismember(img1, only_include);
img2 = img1;
img2(~mask) = 0;
  5 个评论
Walter Roberson
Walter Roberson 2016-4-3
That could happen if none of the values exactly match the list in only_include. For example if you had converted im2double() then the array values would be in the range 0 to 1.
But if you prefer a different implementation method:
img2 = zeros(size(img1), class(img1)) ;
for K = 1 : length(only_include)
mask = img1 == only_include(K) ;
img2(mask) = img(mask) ;
end
h612
h612 2016-4-4
Well this did work. Thank you. I tried using the class type only at first..but it didn't work. Using for loop did. Wondering what is wrong in the previously suggested method.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Display Image 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by