{"id":3138,"date":"2013-06-13T15:13:28","date_gmt":"2013-06-13T19:13:28","guid":{"rendered":"http:\/\/labrigger.com\/blog\/?p=3138"},"modified":"2013-10-04T19:19:25","modified_gmt":"2013-10-04T23:19:25","slug":"local-cross-corr-images","status":"publish","type":"post","link":"http:\/\/labrigger.com\/blog\/2013\/06\/13\/local-cross-corr-images\/","title":{"rendered":"Local cross corr images"},"content":{"rendered":"<p align=\"center\"><a href=\"http:\/\/slslab.com\/papers.html\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/labrigger.com\/blog\/wp-content\/uploads\/2013\/06\/ss1.png\" alt=\"click to go to papers... this is from the Supplement to Smith and Hausser 2010\" width=\"566\" height=\"218\" class=\"aligncenter size-full wp-image-3142\" srcset=\"http:\/\/labrigger.com\/blog\/wp-content\/uploads\/2013\/06\/ss1.png 566w, http:\/\/labrigger.com\/blog\/wp-content\/uploads\/2013\/06\/ss1-300x115.png 300w\" sizes=\"auto, (max-width: 566px) 100vw, 566px\" \/><\/a><\/p>\n<p>One key step in analyzing data form calcium imaging experiments is segmentation (i.e., drawing regions of interest, ROIs). There have been some nice discussions in the literature (<a href=\"http:\/\/www.ncbi.nlm.nih.gov\/pubmed\/18497355\">1<\/a>, <a href=\"http:\/\/www.ncbi.nlm.nih.gov\/pubmed\/19553440\">2<\/a>, <a href=\"http:\/\/www.ncbi.nlm.nih.gov\/pubmed\/19778505\">3<\/a>, <a href=\"http:\/\/www.ncbi.nlm.nih.gov\/pubmed\/20711183\">4<\/a>). Experiments with calcium dyes like OGB-1-AM, and those with genetically encoded indicators like GCaMP, require different approaches for drawing ROIs.<\/p>\n<p>Here&#8217;s some code I&#8217;ve used to generate a first pass of ROIs. The simple idea is that the pixels that are located within cells will be highly correlated because during a fluorescence transient they will all exhibit similar time courses, and other regions (e.g., neuropil, blood vessels, etc.) will not be as correlated.<\/p>\n<p>The input is an X x Y x T 3D matrix (time or frame is the third dim). The output is an X x Y cross corr image. As written below, it looks at the 3 x 3 local neighborhood. If you increase the variable w to 2, then it will look at a 5 x 5 local neighborhood, and so forth.<\/p>\n<pre><font size = 0>\r\nfunction [ccimage]=CrossCorrImage(tc)\r\n\r\nw=1; % window size\r\n\r\n% Initialize and set up parameters\r\nymax=size(tc,1);\r\nxmax=size(tc,2);\r\nnumFrames=size(tc,3);\r\nccimage=zeros(ymax,xmax);\r\n\r\ntic\r\nfor y=1+w:ymax-w\r\n    for x=1+w:xmax-w\r\n        % Center pixel\r\n        thing1 = reshape(tc(y,x,:)-mean(tc(y,x,:),3),[1 1 numFrames]); % Extract center pixel's time course and subtract its mean\r\n        ad_a   = sum(thing1.*thing1,3);    % Auto corr, for normalization later\r\n        \r\n        % Neighborhood\r\n        a = tc(y-w:y+w,x-w:x+w,:);         % Extract the neighborhood\r\n        b = mean(tc(y-w:y+w,x-w:x+w,:),3); % Get its mean\r\n        thing2 = bsxfun(@minus,a,b);       % Subtract its mean\r\n        ad_b = sum(thing2.*thing2,3);      % Auto corr, for normalization later\r\n        \r\n        % Cross corr\r\n        ccs = sum(bsxfun(@times,thing1,thing2),3).\/sqrt(bsxfun(@times,ad_a,ad_b)); % Cross corr with normalization\r\n        ccs((numel(ccs)+1)\/2) = [];        % Delete the middle point\r\n        ccimage(y,x) = mean(ccs(:));       % Get the mean cross corr of the local neighborhood\r\n    end\r\nend\r\ntoc\r\n<\/pre>\n<p><\/font><\/p>\n<p>I then use an adaptive threshold algorithm and the MATLAB function &#8220;bwlabel&#8221; to get a quick, first pass set of ROIs. Once you have your ROIs, you can select <a href=\"http:\/\/www.ncbi.nlm.nih.gov\/pubmed\/2055483\">weights<\/a> for the pixels within the ROI, if need be.<\/p>\n","protected":false},"excerpt":{"rendered":"<p align=\"center\"><a href=\"http:\/\/slslab.com\/papers.html\"><\/a><\/p>\n<p>One key step in analyzing data form calcium imaging experiments is segmentation (i.e., drawing regions of interest, ROIs). There have&#8230;<\/p>\n<div class=\"read-more\"><a href=\"http:\/\/labrigger.com\/blog\/2013\/06\/13\/local-cross-corr-images\/\">Read More<\/a><\/div><\/p>\n","protected":false},"author":1,"featured_media":3142,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[38,26],"class_list":["post-3138","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-software","tag-calcium-imaging","tag-matlab"],"_links":{"self":[{"href":"http:\/\/labrigger.com\/blog\/wp-json\/wp\/v2\/posts\/3138","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/labrigger.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/labrigger.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/labrigger.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/labrigger.com\/blog\/wp-json\/wp\/v2\/comments?post=3138"}],"version-history":[{"count":10,"href":"http:\/\/labrigger.com\/blog\/wp-json\/wp\/v2\/posts\/3138\/revisions"}],"predecessor-version":[{"id":3150,"href":"http:\/\/labrigger.com\/blog\/wp-json\/wp\/v2\/posts\/3138\/revisions\/3150"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/labrigger.com\/blog\/wp-json\/wp\/v2\/media\/3142"}],"wp:attachment":[{"href":"http:\/\/labrigger.com\/blog\/wp-json\/wp\/v2\/media?parent=3138"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/labrigger.com\/blog\/wp-json\/wp\/v2\/categories?post=3138"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/labrigger.com\/blog\/wp-json\/wp\/v2\/tags?post=3138"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}