Finding the variance and covariance value between the bands of the image

Multi tool use
Multi tool use












0















I want to encode without using ready commands. I did something, but the results were too small. I did not compute other bands when errors occurred. I'd appreciate it if you could help.



My V1 (variance-1) value came out at 1,2820183e-05, but with the var() function 91.143653869628900 came out.



format long g
img = imread('Landsat8.tif');
blue = round((im2single(img(:, :, 1))+1)*128);
grn = round((im2single(img(:, :, 2))+1)*128);
red = round((im2single(img(:, :, 3))+1)*128);
blue_r = reshape(blue,[2000*2000,1]);
grn_r = reshape(grn,[2000*2000,1]);
red_r = reshape(red,[2000*2000,1]);

%% Mean
mean1 = sum(blue_r)/(2000*2000);
mean2 = sum(grn_r)/(2000*2000);
mean3 = sum(red_r)/(2000*2000);

%% Variance
sum1 = 0;
for i= 1 : length(2000*2000)
sum1 = sum1 + (blue_r(i) - mean1).^2;
end
V1 = sum1 ./ (length(blue_r));

sum2 = 0;
for i= 1 : length(2000*2000)
sum2 = sum2 + (grn_r(i) - mean2).^2;
end
V2 = sum2 / (length(grn_r));

%% covariance
sum12 = 0;
for i= 1 : length(2000*2000)
sum12 = sum12 + (blue_r(i) - mean1) * (grn_r(i) - mean2);
end
c12 = sum12 / (length(blue_r));









share|improve this question


















  • 1





    length(2000*2000) is 1. You should avoid using fixed values always, it just leads to confusion! Use length(blue_r), that is much better than encoding the size with constants. Also, the first channel is red, not blue.

    – Cris Luengo
    Dec 29 '18 at 21:54













  • Landsat-8 has 11 bands. Its band2:Blue, band3=Green, band4=Red. Thank you Cris.

    – holyboy
    Dec 29 '18 at 22:41













  • Before any computation try to convert variables to double: img = double(img);

    – rahnema1
    Dec 30 '18 at 3:42











  • Thank you rahnema1. Try to 'img = double(img);' It worked and it true.

    – holyboy
    Dec 30 '18 at 21:08
















0















I want to encode without using ready commands. I did something, but the results were too small. I did not compute other bands when errors occurred. I'd appreciate it if you could help.



My V1 (variance-1) value came out at 1,2820183e-05, but with the var() function 91.143653869628900 came out.



format long g
img = imread('Landsat8.tif');
blue = round((im2single(img(:, :, 1))+1)*128);
grn = round((im2single(img(:, :, 2))+1)*128);
red = round((im2single(img(:, :, 3))+1)*128);
blue_r = reshape(blue,[2000*2000,1]);
grn_r = reshape(grn,[2000*2000,1]);
red_r = reshape(red,[2000*2000,1]);

%% Mean
mean1 = sum(blue_r)/(2000*2000);
mean2 = sum(grn_r)/(2000*2000);
mean3 = sum(red_r)/(2000*2000);

%% Variance
sum1 = 0;
for i= 1 : length(2000*2000)
sum1 = sum1 + (blue_r(i) - mean1).^2;
end
V1 = sum1 ./ (length(blue_r));

sum2 = 0;
for i= 1 : length(2000*2000)
sum2 = sum2 + (grn_r(i) - mean2).^2;
end
V2 = sum2 / (length(grn_r));

%% covariance
sum12 = 0;
for i= 1 : length(2000*2000)
sum12 = sum12 + (blue_r(i) - mean1) * (grn_r(i) - mean2);
end
c12 = sum12 / (length(blue_r));









share|improve this question


















  • 1





    length(2000*2000) is 1. You should avoid using fixed values always, it just leads to confusion! Use length(blue_r), that is much better than encoding the size with constants. Also, the first channel is red, not blue.

    – Cris Luengo
    Dec 29 '18 at 21:54













  • Landsat-8 has 11 bands. Its band2:Blue, band3=Green, band4=Red. Thank you Cris.

    – holyboy
    Dec 29 '18 at 22:41













  • Before any computation try to convert variables to double: img = double(img);

    – rahnema1
    Dec 30 '18 at 3:42











  • Thank you rahnema1. Try to 'img = double(img);' It worked and it true.

    – holyboy
    Dec 30 '18 at 21:08














0












0








0








I want to encode without using ready commands. I did something, but the results were too small. I did not compute other bands when errors occurred. I'd appreciate it if you could help.



My V1 (variance-1) value came out at 1,2820183e-05, but with the var() function 91.143653869628900 came out.



format long g
img = imread('Landsat8.tif');
blue = round((im2single(img(:, :, 1))+1)*128);
grn = round((im2single(img(:, :, 2))+1)*128);
red = round((im2single(img(:, :, 3))+1)*128);
blue_r = reshape(blue,[2000*2000,1]);
grn_r = reshape(grn,[2000*2000,1]);
red_r = reshape(red,[2000*2000,1]);

%% Mean
mean1 = sum(blue_r)/(2000*2000);
mean2 = sum(grn_r)/(2000*2000);
mean3 = sum(red_r)/(2000*2000);

%% Variance
sum1 = 0;
for i= 1 : length(2000*2000)
sum1 = sum1 + (blue_r(i) - mean1).^2;
end
V1 = sum1 ./ (length(blue_r));

sum2 = 0;
for i= 1 : length(2000*2000)
sum2 = sum2 + (grn_r(i) - mean2).^2;
end
V2 = sum2 / (length(grn_r));

%% covariance
sum12 = 0;
for i= 1 : length(2000*2000)
sum12 = sum12 + (blue_r(i) - mean1) * (grn_r(i) - mean2);
end
c12 = sum12 / (length(blue_r));









share|improve this question














I want to encode without using ready commands. I did something, but the results were too small. I did not compute other bands when errors occurred. I'd appreciate it if you could help.



My V1 (variance-1) value came out at 1,2820183e-05, but with the var() function 91.143653869628900 came out.



format long g
img = imread('Landsat8.tif');
blue = round((im2single(img(:, :, 1))+1)*128);
grn = round((im2single(img(:, :, 2))+1)*128);
red = round((im2single(img(:, :, 3))+1)*128);
blue_r = reshape(blue,[2000*2000,1]);
grn_r = reshape(grn,[2000*2000,1]);
red_r = reshape(red,[2000*2000,1]);

%% Mean
mean1 = sum(blue_r)/(2000*2000);
mean2 = sum(grn_r)/(2000*2000);
mean3 = sum(red_r)/(2000*2000);

%% Variance
sum1 = 0;
for i= 1 : length(2000*2000)
sum1 = sum1 + (blue_r(i) - mean1).^2;
end
V1 = sum1 ./ (length(blue_r));

sum2 = 0;
for i= 1 : length(2000*2000)
sum2 = sum2 + (grn_r(i) - mean2).^2;
end
V2 = sum2 / (length(grn_r));

%% covariance
sum12 = 0;
for i= 1 : length(2000*2000)
sum12 = sum12 + (blue_r(i) - mean1) * (grn_r(i) - mean2);
end
c12 = sum12 / (length(blue_r));






image matlab covariance variance






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Dec 29 '18 at 21:11









holyboyholyboy

82




82








  • 1





    length(2000*2000) is 1. You should avoid using fixed values always, it just leads to confusion! Use length(blue_r), that is much better than encoding the size with constants. Also, the first channel is red, not blue.

    – Cris Luengo
    Dec 29 '18 at 21:54













  • Landsat-8 has 11 bands. Its band2:Blue, band3=Green, band4=Red. Thank you Cris.

    – holyboy
    Dec 29 '18 at 22:41













  • Before any computation try to convert variables to double: img = double(img);

    – rahnema1
    Dec 30 '18 at 3:42











  • Thank you rahnema1. Try to 'img = double(img);' It worked and it true.

    – holyboy
    Dec 30 '18 at 21:08














  • 1





    length(2000*2000) is 1. You should avoid using fixed values always, it just leads to confusion! Use length(blue_r), that is much better than encoding the size with constants. Also, the first channel is red, not blue.

    – Cris Luengo
    Dec 29 '18 at 21:54













  • Landsat-8 has 11 bands. Its band2:Blue, band3=Green, band4=Red. Thank you Cris.

    – holyboy
    Dec 29 '18 at 22:41













  • Before any computation try to convert variables to double: img = double(img);

    – rahnema1
    Dec 30 '18 at 3:42











  • Thank you rahnema1. Try to 'img = double(img);' It worked and it true.

    – holyboy
    Dec 30 '18 at 21:08








1




1





length(2000*2000) is 1. You should avoid using fixed values always, it just leads to confusion! Use length(blue_r), that is much better than encoding the size with constants. Also, the first channel is red, not blue.

– Cris Luengo
Dec 29 '18 at 21:54







length(2000*2000) is 1. You should avoid using fixed values always, it just leads to confusion! Use length(blue_r), that is much better than encoding the size with constants. Also, the first channel is red, not blue.

– Cris Luengo
Dec 29 '18 at 21:54















Landsat-8 has 11 bands. Its band2:Blue, band3=Green, band4=Red. Thank you Cris.

– holyboy
Dec 29 '18 at 22:41







Landsat-8 has 11 bands. Its band2:Blue, band3=Green, band4=Red. Thank you Cris.

– holyboy
Dec 29 '18 at 22:41















Before any computation try to convert variables to double: img = double(img);

– rahnema1
Dec 30 '18 at 3:42





Before any computation try to convert variables to double: img = double(img);

– rahnema1
Dec 30 '18 at 3:42













Thank you rahnema1. Try to 'img = double(img);' It worked and it true.

– holyboy
Dec 30 '18 at 21:08





Thank you rahnema1. Try to 'img = double(img);' It worked and it true.

– holyboy
Dec 30 '18 at 21:08












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53973368%2ffinding-the-variance-and-covariance-value-between-the-bands-of-the-image%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53973368%2ffinding-the-variance-and-covariance-value-between-the-bands-of-the-image%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







pctgid7GYOlsAg2hEtVi ixmZXAWdXT 0oZ3,lZkP,q5XIH6e,D37BYLnoJV1Vw2 Gbxz1rLKdcu0hg,nJV
dTsn6PFywJyHAfhz4xo,5A09yW,13x14c4mn sVT fd 8IYXlKbI4S98m4S7XetxIzYmf44Z3VWhxggwfPFgu

Popular posts from this blog

Monofisismo

Angular Downloading a file using contenturl with Basic Authentication

Olmecas