필터 지우기
필터 지우기

double precision becomes complex double after calculation

조회 수: 2 (최근 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개)

Community Treasure Hunt

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

Start Hunting!

Translated by