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);
  10 个评论
chaima kadess
chaima kadess 2018-9-11
no ,I am working with a sequence of 16 images and I want to display finally one image of covariance from this 16 images.

请先登录,再进行评论。

回答(1 个)

Walter Roberson
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 个评论
chaima kadess
chaima kadess 2018-9-17
thank you for responding me , but unfortunately it doesn't works , I have a sequence of 16 cardiac images ,the first image will be taken as a reference(c1(i,j)) following this equation : cov(i,j)=(1/T)*((C1(i,j)-mua(i,j))*(AR-muar)) where T is the frame number and mua(i,j) is the mean of the (i j) pixel value in the image series and AR is the mean value of all pixels located in the region of reference and muar is the mean value of the references series.so i am looking to display an image of the calculated covariance . hopefully you can help me mrs.

请先登录,再进行评论。

Community Treasure Hunt

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

Start Hunting!

Translated by