BC_getNaturalMovies.m 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. function [movieSignal]=BC_getNaturalMovies(pixelSize)
  2. %[naturalMovie_output]=BC_getNaturalMovies(loadData)
  3. %this function shows the prinicpal calculation for how to preprocess the
  4. %natural movies from the "CatCam" database. The movie intensity values are
  5. %scaled to have the same mean light intensity as white noise stimulus and
  6. %converted to WeberContrast values. Further, the movie dimensions are
  7. %adapted to match the dimension of the white noise STA filter to later
  8. %perform the prediction with the linear-nonlinear model (LN-model)computed
  9. %with white noise stimulus.
  10. %Inputs:
  11. % pixelSize = pixel size from the white noise stimulus
  12. %
  13. %Outpus: movieSignal = preprocessed movie signal, ready for the
  14. % LN-model analysis
  15. %
  16. %Code by HS Feb 2021
  17. %-------------------------------------------------------------------------------
  18. %% Constants
  19. %movie dimensions of the original tiff files
  20. NxMovie=320; %x pixel tiff movies
  21. NyMovie=240; %y pixel tiff movies
  22. %spatiotemporal white noise dimensions x-y (they are all the same for all
  23. %recorded cells)
  24. monitorXPixels=800; %x pixels of OLED monitor;
  25. monitorYPixels=600; %y pixels of OLED monitor;
  26. NxWhiteNoise=ceil(monitorXPixels/pixelSize); %number of squares shown X dimension
  27. NyWhiteNoise=ceil(monitorYPixels/pixelSize); %number of squares shown Y dimension
  28. %-------------------------------------------------------------------------------
  29. %% 1. Preprocess the movie contrast values
  30. %the movies can be downloaded under the following
  31. %link:https://zenodo.org/record/46481. Each movie frame is presented as an
  32. %individual .tiff file. See documentation.data.pdf for
  33. %further instructions, also which tiff-filename to take per movie.
  34. %Ones the files are downloaded they have to be prepared as follow:
  35. %to show how the movie signal is preprocessed, I generated a random
  36. %example signal of the same dimension as the natural movies (320x240)
  37. nbrFrames=998;
  38. genRandSignal=rand(NyMovie,NxMovie,nbrFrames)*255; %a movie signal (0-255 intensity values, as movie itself)) of 240 (y-dim) 320 (x-dim) and 998 (time frames); thats where you have to put the original movie signal at 320x240xnumber of frames
  39. % %%code to load the tiff files in 1 to 998
  40. % loadTiff='Y:\tiffMovie4';
  41. % indx=1;
  42. % ContentStackDir_tif=dir([loadTiff '\']); %what is inside the folder
  43. % for l=1:1000 %nbr of files in the folder
  44. % if numel(strfind(ContentStackDir_tif(l).name,'.tif'))>0
  45. % %tif files containes one value per pixel -> it is an intensity
  46. % %value for grayscale. So no color information. It is a in uint16
  47. % %imfinfo([ StackDir ImageStack.name '\' ContentStackDir(l).name ])
  48. % %gives you the infos.
  49. % %16-bit intensity images is usually [0, 65535].
  50. % %http://de.mathworks.com/help/matlab/creating_plots/image-types.html
  51. % [ImageStack_tif.imagesOri{indx},cmp]=imread([loadTiff '\' ContentStackDir_tif(l).name ]);%read tiff file
  52. % indx=indx+1;
  53. % end
  54. % end
  55. % genRandSignal=cell2mat(ImageStack_tif.imagesOri);
  56. oneDIamge = reshape(genRandSignal,[],1);
  57. doubleIamge=double(oneDIamge);
  58. normImage=doubleIamge/255; %get intensity values between 0-1
  59. clear oneDIamge doubleIamge
  60. %scale the light intensity to have the same mean as the spatiotemporal white noise stimulus
  61. %which is: 0.5 (see also Method of the mansucript by Schreyer & Gollisch,
  62. %2021)
  63. a=mean(normImage);
  64. dummy = normImage*(0.5/a);
  65. %correct contrast values if needed (this part is done in stimulator program)
  66. dummy(dummy<0) = 0;
  67. dummy(dummy>1) = 1;
  68. %change the vlaues to weber contrast +/1
  69. meanInt=mean(dummy);
  70. movie_WebCont=(dummy-meanInt)/meanInt;
  71. %reshape signal to have again a 3 D structure
  72. movie_WebCont3D = reshape(movie_WebCont,[NyMovie,NxMovie,nbrFrames]);
  73. clear movie_WebCont dummy oneDIamge
  74. %------------------------------------------------------------------------------------------
  75. %% 2. cut the natural movie to have the same dimension as the spatiotemporal white noise
  76. %the movie has a dimension of 320x240, to present the movie on the retina,
  77. %the movie was upsampled by 3 (960x720) and cut out to the OLED resolution
  78. %of 800x600 (cut is from the upper left ->see Documentation.Data.pdf).
  79. %The spatiotemporal white noise was shown at 89x67 checker size resolution.
  80. %And the filter (STA) is at that resolution. We want now to have the same
  81. %resolution for the movies (89x67) so that we can easily convolve the STA with the
  82. %movie.
  83. %To get the dimensions, there are multiple ways. The most intuitive way and easiest to understand is:
  84. %First upsample the image by 3 and cut it to 800x600 OLED resolution, then make
  85. %a mean per 9x9 pixels (for all cells with movie the checker size of the
  86. %white noise stimulus was 9x9 -> see also Documentation_Data.pdf). Then you
  87. %get the same resolution as for the white noise stimulus (89x67).
  88. %Alternative way (maybe faster from the coding side and what I show here) is to directly make the
  89. %average over 3x3 pixels (dont upsample it first by 3) and then cut it to
  90. %89x67 resolution to match the white noise STA (filter).
  91. %%make average per 3x3 movie pixels
  92. NyMovie2=ceil(NyMovie/3);
  93. NxMovie2=ceil(NxMovie/3);
  94. indx=1;%x dimension
  95. indx2=1;%y dimension
  96. movie_WebContSmall=nan(NyMovie2,NxMovie2,size(movie_WebCont3D,3));
  97. for z=1:size(movie_WebCont3D,3) %over movie frames
  98. for x=1:3:size(movie_WebCont3D,2)-2 %over x-axis (first three)
  99. for y=1:3:size(movie_WebCont3D,1)-2 %do the corresponding y-axis
  100. tempx=movie_WebCont3D(y:y+2,x:x+2,z);
  101. movie_WebContSmall(indx2,indx,z)=mean(tempx(:));
  102. indx2=indx2+1;%y dimension
  103. end
  104. indx=indx+1;
  105. indx2=1;
  106. end
  107. indx=1;
  108. indx2=1;
  109. end
  110. %cut the image to a 89x67 resolution (see Documentation_data.pdf) the cut
  111. %is done from the upper left corner
  112. movieSignal=movie_WebContSmall(size(movie_WebContSmall,1)-(NyWhiteNoise)+1:end...
  113. ,1:NxWhiteNoise,:); %starts from y pixel 14 (the first 13 are cut out in stimulator program)
  114. end