Azzera filtri
Azzera filtri

double precision becomes complex double after calculation

2 visualizzazioni (ultimi 30 giorni)
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 Commenti
niranjan v
niranjan v il 17 Mar 2019
i got it sir thank you so much.
can you provide the modified code.
Walter Roberson
Walter Roberson il 17 Mar 2019
No, I cannot provide the modified code as I do not know the proper equations.

Accedi per commentare.

Risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by