Mywarp Code
Mywarp Code
Mywarp Code
% % % % % % % % % % % Functions: generate_rand_mapping_params get_mapping_array compute_polar_coords remapper update_xy get_new_xy Data: ori_map.dat sf_map.dat od_map.dat
% Once you have all of these files, simply type mywarp to run. %% % This program takes in a rigid functional map (orientation, spatial % frequency, and ocular dominance used here) and applies a series of 2 % dimensional Gabor spatial filters to warp the maps. It works by taking % the x,y location of a given cell and applying multiple warps to it based % on its distance (radius) from the Gabor filter center. For each warp, the % the cells polar coordinate is determined with respect to the Gabor filter % center, and then the radius is passed through the integral of the Gabor % equation to determine an r' value which is converted back into Cartesian % coordinates, x',y'. Then, the next warp is carried out using x',y' in the % same manner. Once all warps have been carried out for the particular cell, % the new map takes the value at position x',y' from the original map and % enters it into position x,y in the new, warped map. This is then repeated % for each cell in the cortical sheet. % Gabor equation: 1 + a*cos(sf*x + ph) * exp(x^2/(2*sigma^2)) % % % % % % % % % % % Parameters: a = amplitude of filter sf = spatial frequency of cosine component of Gabor filter ph = phase of cosine component of Gabor filter sigma = std dv for Gaussian component of Gabor filter The parameters for each Gabor filter, including x,y position of their centers, are randomly generated. The equation is added to 1 so that, on average, the integrated Gabor filter that constitutes the map function becomes a straight line at large radii. That is, distances far from the Gabor filter center have r' values that are close, if not exactly equal to, r.
% Sets parameters. nx = 224; % number of cells in cortical layer along x dimension ny = 112; % number of cells along corical layer along y dimension nwarps = 20; % number of warps to compute on map n = round(sqrt(nx^2 + ny^2)); % max range of Gabor filter/map function step_size = 1; % step size for manual, discritized integration map1 = 0:step_size:n-1; % array index reference values for map function
fprintf('\nGENERATING PARAMETERS & COMPUTING MAP FUNCTIONS\n'); fprintf('\n'); % Generates random parameter values for each warp step and generates % map functions. Map functions are defined as the integral of a particular % Gabor equation used to compute new map values according to radius from % Gabor filter center. map_functions = zeros(nwarps, n); % map functions for warps warp_centers = zeros(nwarps, 2); % (x,y) locations of warp centers for i = 1:nwarps; [a, sigma, sf, ph, cx, cy] = generate_rand_mapping_params(n,nx,ny); warp_centers(i,:) = [cx, cy]; % cx = x location of filter center % cy = y location of filter center map_functions(i,:) = get_mapping_array(a, sigma, sf, ph, n); end % Generates grid for testing. test_map = ones(ny, nx); warped_test_map = zeros(ny, nx); for i = 1:ny; for j = 1:nx; if mod(i,4) == 0 || mod(j,4) == 0 test_map(i,j) = 0; end end end % Loads maps and prepares warped versions. load ori_map.dat warped_ori_map = zeros(size(ori_map)); load sf_map.dat warped_sf_map = zeros(size(sf_map)); load od_map.dat warped_od_map = zeros(size(od_map)); fprintf('WARPING MAP (this may take a while)\n'); % Applies nwarps cell by cell using map functions to test grid and each map. for x = 1:nx for y = 1:ny mod_x = x; mod_y = y; for w = 1:nwarps; cx = warp_centers(w,1); cy = warp_centers(w,2); [r, theta] = compute_polar_coords(mod_x, mod_y, cx, cy); r_prime = remapper(map_functions(w,:), step_size,r); if isempty(r_prime) r_prime = r; end [mod_x, mod_y] = update_xy(r_prime, theta, cx, cy); end [new_x, new_y] = get_new_xy(mod_x, mod_y, nx, ny); warped_ori_map(y,x) = ori_map(new_y, new_x); warped_sf_map(y,x) = sf_map(new_y, new_x); warped_od_map(y,x) = od_map(new_y, new_x);
warped_test_map(y,x) = test_map(new_y, new_x); end end % Plots warped maps against originals. figure(1) subplot(1,2,1) image(test_map, 'CDataMapping','scaled'); colormap(gray); title('Grid Test Original'); subplot(1,2,2) image(warped_test_map, 'CDataMapping','scaled'); title('Grid Test Warp'); figure(3) subplot(1,2,1) image(ori_map, 'CDataMapping','scaled'); title('Orientation Map Original') subplot(1,2,2) image(warped_ori_map, 'CDataMapping','scaled'); title('Orientation Map Warp') figure(4) subplot(1,2,1) image(sf_map, 'CDataMapping','scaled'); title('Spatial Frequency Map Original') subplot(1,2,2) image(warped_sf_map, 'CDataMapping','scaled'); title('Spatial Frequency Map Warp') figure(5) subplot(1,2,1) image(od_map, 'CDataMapping','scaled'); title('Ocular Dominance Map Original') subplot(1,2,2) image(warped_od_map, 'CDataMapping','scaled'); title('Ocular Dominance Map Warp') % Demonstration of Gabor filter function (last instance of parameters). figure(6) y = 1 + a*cos(sf*map1 + ph) .* exp(-map1.^2/(2*sigma^2)); plot(map1, y) title('Gabor Filter Example'); xlabel('Radius (r)') ylabel('Warp Magnitude (grid(cell) units)') % Integrates Gabor filter for demonstration of mapping function. map_function = get_mapping_array(a, sigma, sf, ph, n); % Demonstration of mapping function with respect to y = x. figure(7) plot(map1, map_function, map1, map1) title('Map Function: Integrated Gabor Filter'); xlabel('Radius (r)') ylabel('New Radius (r")')