double precision becomes complex double after calculation

3 ビュー (過去 30 日間)
niranjan v
niranjan v 2019 年 3 月 17 日
コメント済み: Walter Roberson 2019 年 3 月 17 日
The outputs for a becomes complex double after calculation. However, it should be double precision since I am just raising the power of the element. Is there any possibility to fix it? .
i got a as a comlex double and in b i got NaN values.
tic
clear;
close all;
I=imread('Lenna.tiff');
if size(I,3)==3
I=rgb2gray(I);
end
k=I;
%size of image
[M,N]=size(I);
%convert to double
I=double(I);
Y=zeros(M,N);
binimg=de2bi(I,'left-msb');
binimg1 = binimg(:, 1:end-3);
binimg2 = bi2de(binimg1,'left-msb');
finalimg = reshape(binimg2,size(I));
I=finalimg;
% ----------------------------------------------------
%% Block Truncation Coding Compression
blksize=2; %Block Size
mu=colfilt(I,[blksize,blksize],'distinct',@(x) ones(blksize^2,1)*mean(x));
sigma=colfilt(I,[blksize,blksize],'distinct',@(x) ones(blksize^2,1)*std(x));
q=I>mu;
q=colfilt(q,[blksize,blksize],'distinct',@(x) ones(blksize^2,1)*sum(x));
m=blksize^2; %length*width of block
a=mu-sigma.*(sqrt(q./m-q)); %low mean
b=mu+sigma.*(sqrt(m-q./q)); %high mean
H=I>=mu; %elements of Bitmap
Y(H)=a(H);
Y(~H)=b(~H);
Y=uint8(Y);
% ----------------------------------------------------------------------------
% Dividing into blocks
% ----------------------------------------------------------------------------
if ismatrix(Y)
blocks2x2 = mat2cell(Y, 2 * ones(1,256), 2 * ones(1,256) );
else
blocks2x2 = mat2cell(Y, 2 * ones(1,256), 2*ones(1,256), size(Y,3) );
end
% -----------------------------------------------------------------------------
subplot(1,2,1),imshow(k);title('orginal image');
subplot(1,2,2),imshow(Y);title('compressed image');
%output BTC image
% dPSNR=psnrr(I,Y);
toc
  3 件のコメント
niranjan v
niranjan v 2019 年 3 月 17 日
i got it sir thank you so much.
can you provide the modified code.
Walter Roberson
Walter Roberson 2019 年 3 月 17 日
No, I cannot provide the modified code as I do not know the proper equations.

サインインしてコメントする。

回答 (0 件)

カテゴリ

Help Center および File ExchangeConvert Image Type についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by