I am trying to display an image of covariance(covariance map) using this code but I receive a false result , please would you help me with this (I need this for my master degree)
2 次查看(过去 30 天)
显示 更早的评论
clc
close all
clear all
img = imread('C:\test\image\image1.jpg'); %lire l'image de reference
I = rgb2gray(img); %convertir en niveau de gris
I1 = medfilt2(I, [5 5]);
C=imcrop(I1, [18.5 29.5 31 29]); %imcrop an ROI(left ventricular)
[m,n]=size(C);
for i=1:m
for j=1:n
for num=1:16
file=['image', num2str(num),'.','jpg'];
im = im2double(imread(fullfile('C:\test\image', file)));
im = rgb2gray(im); %convertir en niveau de gris
I2 = medfilt2(im, [5 5]);
C=imcrop(I2,[18.5 29.5 31 29]);
a(i,j)= C(i,j);
C1 = imcrop(C, [20.5 16.5 5 4]); %ROI2 inside the first ROI
[m1,n1]= size(C1);
end
mua(i,j)=((1/16)*(sum(C(i,j))));
end
end
for num=1:16
for i=1:m1
for j=1:n1
a1(i,j)=C1(i,j);
end
end
AR(num)=((1/(m1*n1))*(a1(i,j))); %%%%%%%%%%%%
end
% %
for i=1:m1
for j=1:n1
muar =((1/16)*sum(AR));
end
end
for i=1:m1
for j=1:n1
for num=1:16
cov(i,j) = sum((a1(i,j) - mua(i,j))*(AR - muar));
end
covtot(i,j) = ((1/16)*sum(cov(i,j)));
end
end
figure(1);
imagesc(covtot),title('image de covariance'),
colorbar, colormap(jet);
回答(1 个)
Walter Roberson
2018-9-11
You should replace a bunch of your code.
numimg = 16;
mut = zeros(m, n);
for num = 1:numimg
file = ['image', num2str(num),'.','jpg'];
im = im2double(imread(fullfile('C:\test\image', file)));
im = rgb2gray(im); %convertir en niveau de gris
I2 = medfilt2(im, [5 5]);
C = imcrop(I2,[18.5 29.5 31 29]);
mut = mut + C;
C1 = imcrop(C, [20.5 16.5 5 4]); %ROI2 inside the first ROI
AR(num) = mean2(C1);
end
mua = mut ./ numimg;
I had to make an assumption here about what you were calculating with mua.
3 个评论
Walter Roberson
2018-9-12
If it is the average of a(i,j) over all of the images, then that is what I have the code calculate.
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!