getRFIm.m 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. function rfIm = getRFIm(xRF, yRF, varargin)
  2. if ~isempty(varargin)
  3. normFactor = varargin{1};
  4. else
  5. normFactor = max(abs(([xRF(:);yRF(:)])));
  6. end
  7. % Normalize the tuning curves.
  8. xRFArray = repmat(xRF / normFactor, fliplr(size(yRF)));
  9. yRFArray = repmat(yRF' / normFactor, size(xRF));
  10. % In case of saturation set to one.
  11. xRFArray(xRFArray >= 1) = 1;
  12. yRFArray(yRFArray >= 1) = 1;
  13. xRFArray(xRFArray <= -1) = -1;
  14. yRFArray(yRFArray <= -1) = -1;
  15. % Split arrays into nonnegative and nonpositive ones.
  16. [negYRFArray, posYRFArray] = rectifyArray(yRFArray);
  17. [negXRFArray, posXRFArray] = rectifyArray(xRFArray);
  18. %%
  19. % Define image of negative RF, product of negative gives positive.
  20. negRF = negXRFArray .* negYRFArray;
  21. negIm = getSameSignRFIm(negRF, [60 80 0]);
  22. % Define image of positive RF.
  23. posRF = posXRFArray .* posYRFArray;
  24. posIm = getSameSignRFIm(posRF, [160 40 0]);
  25. % Define image of positive X and negative Y RF, and vice versa.
  26. posNegIm = getSameSignRFIm(posXRFArray .* abs(negYRFArray), [0 0 0]);
  27. negPosIm = getSameSignRFIm(abs(negXRFArray) .* posYRFArray, [0 0 0]);
  28. rfIm = negIm + posIm + posNegIm + negPosIm;
  29. end
  30. %%
  31. function [nonPosArray, nonNegArray] = rectifyArray(array)
  32. nonPosArray = array;
  33. nonPosArray(nonPosArray > 0) = 0;
  34. nonNegArray = array;
  35. nonNegArray(nonNegArray < 0) = 0;
  36. end
  37. function rfIm = getSameSignRFIm(rfArray, hclColor)
  38. % For hcl many colrs have artifacts in low luminances, the
  39. % previous choice of colors provides near optimal solution to the
  40. % problem, and tries to be colorblind-friendly.
  41. % Assign hcl values, first luminance.
  42. rfIm(:, :, 3) = rfArray * 100;
  43. % Now make the rest with hue and chroma.
  44. rfIm(:, :, 1) = rfArray ./ rfArray * hclColor(1);
  45. rfIm(:, :, 2) = rfArray ./ rfArray * hclColor(2);
  46. % Remove the artifacts of division by zero.
  47. rfIm(isnan(rfIm)) = 0;
  48. for i = 1: size(rfIm, 1)
  49. for j = 1: size(rfIm, 2)
  50. rfIm(i, j, :) = hcl2rgb(rfIm(i, j, 1), rfIm(i, j, 2), ...
  51. rfIm(i, j, 3)) / 255;
  52. end
  53. end
  54. % Set zero values to black to avoid conversion problems.
  55. rfIm(rfArray == 0) = 0;
  56. end