From fd7d21d4e04d34654c1b9438b2891817d7ee1a65 Mon Sep 17 00:00:00 2001 From: julianarhee Date: Wed, 22 Jun 2016 20:15:45 -0400 Subject: [PATCH] fixed bad flag statements for saving new samples, plus fixed small errors to sample_morphs. adding CE's MDS script --- matlab/MDS_from_pdist_V1features.m | 68 +++---- matlab/MDS_from_pdist_V1features.m~ | 191 ++++++++++++++++++ matlab/MDS_from_pdist_pixels.m | 18 +- matlab/MDSfromDistMatrix.m | 152 ++++++++++++++ ...eImageIntoBackgroundWithGivenDimensions.m~ | 74 ------- matlab/ResizeBlobRatStims_General_morphs.m | 6 +- matlab/batch_convert_pov.m | 12 +- modules/correlation/build/lib/correlation.py | 2 +- modules/correlation/correlation.py | 2 +- modules/euclid/build/lib/euclid.py | 2 +- modules/euclid/euclid.py | 2 +- modules/projection/build/lib/projection.py | 7 +- modules/projection/projection.py | 7 +- sample_morphs.py | 3 + 14 files changed, 417 insertions(+), 129 deletions(-) create mode 100644 matlab/MDS_from_pdist_V1features.m~ create mode 100644 matlab/MDSfromDistMatrix.m delete mode 100644 matlab/PasteImageIntoBackgroundWithGivenDimensions.m~ diff --git a/matlab/MDS_from_pdist_V1features.m b/matlab/MDS_from_pdist_V1features.m index 102d18c..e91ac24 100644 --- a/matlab/MDS_from_pdist_V1features.m +++ b/matlab/MDS_from_pdist_V1features.m @@ -12,10 +12,10 @@ if strfind(user_name, 'rhee') % ON DIXIE base_root = '/nas/volume1/behavior/stimuli/pnas_morphs/samples/'; %,... - feature_base_root = '/nas/volume1/behavior/stimuli/pnas_morphs/V1_features/'; + feature_base_root = '/nas/volume1/behavior/stimuli/pnas_morphs/V1features/'; else base_root = '/media/nas/volume1/behavior/stimuli/pnas_morphs/samples/'; - feature_base_root = '/media/nas/volume1/behavior/stimuli/pnas_morphs/V1_features/'; + feature_base_root = '/media/nas/volume1/behavior/stimuli/pnas_morphs/V1features/'; end sample_dirs = dir(base_root); @@ -40,37 +40,27 @@ D.sampled_feature = cond_info{1}; D.sampled_distance = cond_info{2}; D.sampled_comparison = cond_info{3}; - - % FIX THIS FOR V1 referencing: -% if strfind(stimset, 'pov20') -% nstims = 22; -% feature_root = [feature_base_root, 'pov20/']; -% else -% nstims = 2002; -% if strfind(stimset, 'pixels_') -% % Samples generated with python (i.e,. not using -% % V1-features) do not have associated sample_idxs... -% % Instead, use V1 features created for specific stimsets: -% feature_root = [feature_base_root, sprintf('%s_%s20', D.sampled_distance, D.sampled_comparison)] -% else -% feature_root = [feature_base_root, 'morph2000_gray_resize/']; -% end -% end - if strfind(stimset, 'v1_') - nstims = 2002; - feature_root = [feature_base_root, 'morph2000_gray_resize/']; + + if strfind(stimset, 'V1_euclid_neighbor') + continue; + end +% + if strfind(stimset, 'V1_') + + feature_root = [feature_base_root, 'pov2000_final/']; else - nstims = 22; + % Samples generated with python (i.e,. not using % V1-features) do not have associated sample_idxs... % Instead, use V1 features created for specific stimsets: - feature_root = [feature_base_root, sprintf('%s_%s20/', D.sampled_distance, D.sampled_comparison)] + feature_root = [feature_base_root, stimset, '/']; end - D.nstims = nstims + + %D.nstims = nstims % out_root=fullfile(parts{1:end-2}); - out_root = [strjoin(parts(1:end-3), '/'), '/figures/']; + out_root = [strjoin(parts(1:end-3), '/'), '/figures/MDS/']; if ~isdir(out_root) mkdir(out_root) @@ -106,11 +96,16 @@ mfiles{m} = main_mfiles(m).name; end - curr_mfile_idx = ~cellfun('isempty', strfind(mfiles, sprintf('_%s_%s_%i', D.sampled_distance, D.sampled_comparison, D.nstims))) + curr_mfile_idx = ~cellfun('isempty', strfind(mfiles, sprintf('%s_%s_%s', D.sampled_feature, D.sampled_distance, D.sampled_comparison))) curr_mfile = mfiles(curr_mfile_idx); - curr_mfile = curr_mfile{1} + if any(curr_mfile_idx) + curr_mfile = curr_mfile{1} + else + curr_mfile = ''; + end + - if strfind(curr_mfile, '_fixedref') + if strfind(curr_mfile, '_fixedref') & strfind(curr_mfile, 'V1_') sprintf('Skipping MDS for bad-sampling of %s stimset...', curr_mfile) continue; end @@ -119,7 +114,7 @@ if isempty(curr_mfile) M = struct(); M.sample_idxs = linspace(1, length(imnames), length(imnames)); - curr_mfile = sprintf('pdistmat_%s_%s_%i.mat', D.sampled_distance, D.sampled_comparison, D.nstims); + curr_mfile = sprintf('%s_%s_%s.mat', D.sampled_feature, D.sampled_distance, D.sampled_comparison); save_new = 1; else @@ -164,12 +159,13 @@ %plot w/ color scatter plot colorList={'r','b'}; + c = linspace(1,5,nsamples); sz=10; hF=figure; hold all - scatter(distMatrixMap(1:nsamples,1),distMatrixMap(1:nsamples,2),sz,colorList{1},'o') - scatter(distMatrixMap(1,1),distMatrixMap(1,2),sz,'b','o') + scatter(distMatrixMap(1:nsamples,1),distMatrixMap(1:nsamples,2),sz,c,'o') + scatter(distMatrixMap(1,1),distMatrixMap(1,2),sz,'k','*') title(sprintf('_%s_MDS_%s_scatter.png', input, stimset)) saveas(hF,[out_root,corrType,sprintf('_%s_MDS_%s_scatter.png', input, stimset)]) outstring = [out_root,corrType,sprintf('_%s_MDS_%s_scatter.png', input, stimset)]; @@ -178,8 +174,11 @@ %plot w/ images % im_source_root='/media/nas/volume1/behavior/stimuli/pnas_morphs/pov20_gray_resize/'; % im_source_root = source_root; - - sz=.03; + if strfind(corrType, 'euclidean') + sz = 5; + else + sz = .05; + end hF=figure; hold all for i=1:length(imnames) @@ -195,7 +194,8 @@ end colormap('gray') - title('MDS map') + %title('MDS map') + title(sprintf('_%s_MDS_%s_scatter.png', input, stimset)) saveas(hF,[out_root,corrType,sprintf('_%s_MDS_%s.png', input, stimset)]) outstring = [out_root,corrType,sprintf('_%s_MDS_%s.png', input, stimset)]; diff --git a/matlab/MDS_from_pdist_V1features.m~ b/matlab/MDS_from_pdist_V1features.m~ new file mode 100644 index 0000000..743b469 --- /dev/null +++ b/matlab/MDS_from_pdist_V1features.m~ @@ -0,0 +1,191 @@ +clear all +close all +clc + +addpath(genpath('./helpers')) +addpath(genpath('./hmaxMatlab')) + +corrTypes= {'correlation', 'euclidean'}; %{'correlation', 'euclidean'}; +input = 'V1features'; + +[~, user_name] = system('whoami'); + +if strfind(user_name, 'rhee') % ON DIXIE + base_root = '/nas/volume1/behavior/stimuli/pnas_morphs/samples/'; %,... + feature_base_root = '/nas/volume1/behavior/stimuli/pnas_morphs/V1features/'; +else + base_root = '/media/nas/volume1/behavior/stimuli/pnas_morphs/samples/'; + feature_base_root = '/media/nas/volume1/behavior/stimuli/pnas_morphs/V1features/'; +end + +sample_dirs = dir(base_root); +sample_dirs = sample_dirs([sample_dirs.isdir]); +sample_dirs = sample_dirs(arrayfun(@(x) x.name(1), sample_dirs) ~= '.'); + +D = struct(); + +for CORR=1:length(corrTypes) + corrType = corrTypes{CORR}; + + for root=1:length(sample_dirs) + clear dist_mat D M + source_root = [base_root, sample_dirs(root).name, '/']; + + parts = strsplit(source_root,'/'); + stimset = parts{end-1}; + + cond_info = strsplit(stimset, '_'); + D.source_root = source_root; + D.stimset = stimset; + D.sampled_feature = cond_info{1}; + D.sampled_distance = cond_info{2}; + D.sampled_comparison = cond_info{3}; + + if strfind(stimset, 'v1_') + nstims = 2002; + feature_root = [, ]; + else + nstims = 22; + % Samples generated with python (i.e,. not using + % V1-features) do not have associated sample_idxs... + % Instead, use V1 features created for specific stimsets: + feature_root = [feature_base_root, sprintf('%s_%s20/', D.sampled_distance, D.sampled_comparison)] + end + + D.nstims = nstims + +% out_root=fullfile(parts{1:end-2}); + out_root = [strjoin(parts(1:end-3), '/'), '/figures/']; + + if ~isdir(out_root) + mkdir(out_root) + sprintf('Created output dir: %s', out_root) + end + + sprintf('SOURCE: %s\nSTIMSET: %s\nCORR: %s | INPUT: %s\n', source_root, stimset, corrType, input) + + % Get the stimuli for pdist matrix: +% if strfind(input, 'pixels') % Compare images pixel-wise +% iminfo = dir([source_root,'*.png']); +% +% elseif strfind(input, 'V1features') +% iminfo = dir([base_root,'*.mat']); % Compare V1-feature responses to image +% end + + iminfo = dir([source_root,'/*.png']); + imnames = cell(1, length(iminfo)); + for i=1:length(iminfo) + imnames{i} = iminfo(i).name; + end + imnames = sort_nat(imnames); + sprintf('N sampled image: %i', length(imnames)) + + % Load main .mat for V1 feature vector to get the sample_idxs (need + % this to grab the correct V1-feature-vector from source bank. + + % NO .MAT for any _fixedref, since sampling looked terrible + main_mfiles = dir([base_root,'*.mat']); + mfiles = cell(1,length(main_mfiles)); + for m=1:length(main_mfiles) + %curr_mfile = main_mfiles(m).name; + mfiles{m} = main_mfiles(m).name; + end + + curr_mfile_idx = ~cellfun('isempty', strfind(mfiles, sprintf('_%s_%s_%i', D.sampled_distance, D.sampled_comparison, D.nstims))) + curr_mfile = mfiles(curr_mfile_idx); + curr_mfile = curr_mfile{1} + + if strfind(curr_mfile, '_fixedref') + sprintf('Skipping MDS for bad-sampling of %s stimset...', curr_mfile) + continue; + end + + save_new = 0; + if isempty(curr_mfile) + M = struct(); + M.sample_idxs = linspace(1, length(imnames), length(imnames)); + curr_mfile = sprintf('pdistmat_%s_%s_%i.mat', D.sampled_distance, D.sampled_comparison, D.nstims); + save_new = 1; + else + + M = load([base_root, curr_mfile]); + if isfield(M, 'M') + M = M.M; + end + end + + if isfield(M, 'pdist') && isfield(M.pdist, corrType) + dist_mat = M.pdist.(corrType); + nsamples = length(M.sample_idxs); + else + if ~isfield(M, 'pdist') + M.pdist = struct(); + end + sampled_feature_vects = []; + for idx=1:length(M.sample_idxs) + curr_feat = load([feature_root, sprintf('V1_features_morph%i.mat', (M.sample_idxs(idx)-1))]); + sampled_feature_vects = [sampled_feature_vects; curr_feat.featureVector]; % F = [F curr_feat.featureVector']; doesn't work.. too big + end + nsamples = length(M.sample_idxs); + + dist_mat = pdist(sampled_feature_vects, corrType); + dist_mat=squareform(dist_mat); + + %get rid of float-point artifacts that make matrix unsymmetric + dist_mat=round(dist_mat*10000)/10000; + M.pdist.(corrType) = dist_mat; + if save_new==1 + save([base_root, curr_mfile], 'M') + else + save([base_root, curr_mfile], 'M', '-append') + end + end + + + % opts = statset('Display','iter', 'MaxIter', 1500); + opts = statset('MaxIter', 5000); + + [distMatrixMap,distMatrixStress]=mdscale(dist_mat, 2, 'Options', opts); + + %plot w/ color scatter plot + colorList={'r','b'}; + sz=10; + hF=figure; + hold all + + scatter(distMatrixMap(1:nsamples,1),distMatrixMap(1:nsamples,2),sz,colorList{1},'o') + scatter(distMatrixMap(1,1),distMatrixMap(1,2),sz,'b','o') + title(sprintf('_%s_MDS_%s_scatter.png', input, stimset)) + saveas(hF,[out_root,corrType,sprintf('_%s_MDS_%s_scatter.png', input, stimset)]) + outstring = [out_root,corrType,sprintf('_%s_MDS_%s_scatter.png', input, stimset)]; + sprintf('Saved SCATTER to:\n%s', outstring) + + %plot w/ images + % im_source_root='/media/nas/volume1/behavior/stimuli/pnas_morphs/pov20_gray_resize/'; +% im_source_root = source_root; + + sz=.03; + hF=figure; + hold all + for i=1:length(imnames) + imName=[source_root,imnames{i}]; + im0=double(imread(imName)); + centerX=distMatrixMap(i,1); + centerY=distMatrixMap(i,2); + X1=centerX-(sz/2)*2; + X2=centerX+(sz/2)*2; + Y1=centerY-(sz/2); + Y2=centerY+(sz/2); + image([X2, X1],[Y2, Y1],(im0/255)*64) + end + + colormap('gray') + title('MDS map') + + saveas(hF,[out_root,corrType,sprintf('_%s_MDS_%s.png', input, stimset)]) + outstring = [out_root,corrType,sprintf('_%s_MDS_%s.png', input, stimset)]; + sprintf('Saved IMAGES to:\n%s', outstring) + + end + +end diff --git a/matlab/MDS_from_pdist_pixels.m b/matlab/MDS_from_pdist_pixels.m index 777704a..dee2a70 100644 --- a/matlab/MDS_from_pdist_pixels.m +++ b/matlab/MDS_from_pdist_pixels.m @@ -21,6 +21,7 @@ sample_dirs = dir(base_root); sample_dirs = sample_dirs([sample_dirs.isdir]); sample_dirs = sample_dirs(arrayfun(@(x) x.name(1), sample_dirs) ~= '.'); +sample_dirs = sample_dirs(arrayfun(@(x) x.name(1), sample_dirs) ~= '.'); D = struct(); @@ -31,6 +32,9 @@ clear dist_mat D M source_root = [base_root, sample_dirs(root).name, '/']; + if strfind(source_root, 'V1') + continue; + end parts = strsplit(source_root,'/'); stimset = parts{end-1}; @@ -171,12 +175,14 @@ %plot w/ color scatter plot colorList={'r','b'}; + c = linspace(1,5,nsamples); + sz=10; hF=figure; hold all - - scatter(distMatrixMap(1:nsamples,1),distMatrixMap(1:nsamples,2),sz,colorList{1},'o') - scatter(distMatrixMap(1,1),distMatrixMap(1,2),sz,'b','o') + + scatter(distMatrixMap(1:nsamples,1),distMatrixMap(1:nsamples,2),sz,c,'o') + scatter(distMatrixMap(1,1),distMatrixMap(1,2),sz,'k','*') title(sprintf('_%s_MDS_%s_scatter.png', input, stimset)) saveas(hF,[out_root,corrType,sprintf('_%s_MDS_%s_scatter.png', input, stimset)]) outstring = [out_root,corrType,sprintf('_%s_MDS_%s_scatter.png', input, stimset)]; @@ -186,12 +192,12 @@ % im_source_root='/media/nas/volume1/behavior/stimuli/pnas_morphs/pov20_gray_resize/'; % im_source_root = source_root; - sz=.03; + sz=.1; hF=figure; hold all - for i=1:length(imnames) + for i=1:2 %length(imnames) imName=[source_root,imnames{i}]; - im0=double(imread(imName)); + im0=imread(imName); centerX=distMatrixMap(i,1); centerY=distMatrixMap(i,2); X1=centerX-(sz/2)*2; diff --git a/matlab/MDSfromDistMatrix.m b/matlab/MDSfromDistMatrix.m new file mode 100644 index 0000000..a9310e6 --- /dev/null +++ b/matlab/MDSfromDistMatrix.m @@ -0,0 +1,152 @@ +clear all +close all + +% source_root='/media/nas/volume1/behavior/stimuli/pnas_morphs/pov20/pov20_gray_resize/'; + +% source_root='/media/nas/volume1/behavior/stimuli/pnas_morphs/V1_features/morph2000_gray_resize_samples_pcorr_neighbor/'; +% % source_root='/media/nas/volume1/behavior/stimuli/pnas_morphs/V1_features/morph2000_gray_resize_samples_pcorr/'; + +% source_root='/media/nas/volume1/behavior/stimuli/pnas_morphs/V1_features/samples/morph2000_samples_pcorr_neighbor/'; +% source_root='/media/nas/volume1/behavior/stimuli/pnas_morphs/V1_features/samples/morph2000_samples_euclid_neighbor/'; + +% source_root='/media/nas/volume1/behavior/stimuli/pnas_morphs/morph2000_gray_resize_samples_corr/'; +% source_root='/media/nas/volume1/behavior/stimuli/pnas_morphs/morph2000_gray_resize_samples_euclid/'; + +% source_root='/media/nas/volume1/behavior/stimuli/pnas_morphs/morph2000_gray_resize_samples_correl_relative/'; +% source_root='/media/nas/volume1/behavior/stimuli/pnas_morphs/morph2000_gray_resize_samples_euclid_relative/'; +% source_root='/media/nas/volume1/behavior/stimuli/pnas_morphs/morph2000_gray_resize_samples_euclid_rel2/'; + +% source_root='/media/nas/volume1/behavior/stimuli/pnas_morphs/morph2000_gray_resize_samples_project/'; + +% source_root='/media/nas/volume1/behavior/stimuli/pnas_morphs/pixels/samples/test_euclid_fixedref/'; +% source_root='/media/nas/volume1/behavior/stimuli/pnas_morphs/pixels/samples/test_euclid_neighbor/'; +% source_root='/media/nas/volume1/behavior/stimuli/pnas_morphs/pixels/samples/test_project/'; +% source_root='/media/nas/volume1/behavior/stimuli/pnas_morphs/pixels/samples/test_correl/'; +% source_root='/media/nas/volume1/behavior/stimuli/pnas_morphs/pixels/samples/test_correl_fixedref/'; + + +source_root='/media/nas/volume1/behavior/stimuli/pnas_morphs/samples/pixels_euclid_fixedref/'; + +parts = strsplit(source_root,'/'); +stimset = parts{end-1} + +out_root=fullfile(parts{1:end-3}); +out_root = ['/', out_root,'/figures/'] + +if ~isdir(out_root) + mkdir(out_root) + sprintf('Created output dir: %s', out_root) +end + +% Get the stimuli for comp matrix: +base_root = ['/', fullfile(parts{1:end-2}), '/figures']; + +input = 'pixel'; +% input = 'V1features'; + +iminfo = dir([source_root,'*.png']); +imnames = cell(1, length(iminfo)); +for i=1:length(iminfo) + imnames{i} = iminfo(i).name; +end +imnames = sort_nat(imnames); + +% corrType='correlation'; +corrType='euclidean'; +%corrType='Spearman'; +% load([out_rootoot,corrType,'Corr_V1features_distMatrix']) + + +% load .mat for V1 feature vector +if strfind(input, 'V1features') + main_mfile = dir([base_root,'*.mat']); + for i=1:length(main_mfile) + main_mfile_name = main_mfile(i).name; + if strfind(main_mfile_name, '_pcorr_neighbor') + load([base_root, main_mfile_name]) + end + end + + feat_root = '/media/nas/volume1/behavior/stimuli/pnas_morphs/V1_features/morph2000_gray_resize/'; + F = []; + for idx=1:length(sample_idxs) + curr_feat = load([feat_root, sprintf('V1_features_morph%i.mat', idx)]); + F = [F; curr_feat.featureVector]; + % F = [F curr_feat.featureVector']; doesn't work.. too big + end + nsamples = length(sample_idxs); + +else + + F = []; + for i=1:length(imnames) + curr_im = double(imread([source_root, imnames{i}])); + F = [F; reshape(curr_im, 1, numel(curr_im))]; + end + nsamples = length(imnames); + +end + +% if strfind(corrType, 'Pearson') +% dist_mat = corr(F); +% else +sprintf('Using distance metric: %s', corrType) +dist_mat = pdist(F, corrType); +% end + +dist_mat=squareform(dist_mat); + +%get rid of float-point artifacts that make matrix unsymmetric +dist_mat=round(dist_mat*10000)/10000; + +opts = statset('Display','iter', 'MaxIter', 50000); +% opts = statset('MaxIter', 10000); + +[distMatrixMap,distMatrixStress]=mdscale(dist_mat,2, 'Options', opts); + + +%plot w/ color scatter plot +colorList={'r','b'}; +sz=10; +hF=figure; +hold all +scatter(distMatrixMap(1:length(nsamples),1),distMatrixMap(1:length(nsamples),2),sz,colorList{1},'o') +scatter(distMatrixMap(length(nsamples)+1:end,1),distMatrixMap(length(nsamples)+1:end,2),sz,colorList{2},'o') + +saveas(hF,[out_root,corrType,sprintf('Corr_%s_MDS_%s_scatter.png', input, stimset)]) + +%plot w/ images +% imSourceRoot='/home/cesar/Documents/Stimuli/static/trainingObjects/Blobs_HorizontalAzimuthRotation/'; +% im_source_root='/media/nas/volume1/behavior/stimuli/pnas_morphs/pov20_gray_resize/'; +im_source_root = source_root; + +sz=.03; +hF=figure;hold all +for i=1:length(imnames) + imName=[im_source_root,imnames{i}]; + im0=double(imread(imName)); + centerX=distMatrixMap(i,1); + centerY=distMatrixMap(i,2); + X1=centerX-(sz/2)*2; + X2=centerX+(sz/2)*2; + Y1=centerY-(sz/2); + Y2=centerY+(sz/2); + image([X2, X1],[Y2, Y1],(im0/255)*64) +end +% axis([-.4 .4 -.4 .4]) +% +% for i=1:length(fnames) +% imName=[im_source_root,fnames{i}]; +% im0=double(imread(imName)); +% centerX=distMatrixMap(length(fnames)+i,1); +% centerY=distMatrixMap(length(fnames)+i,2); +% X1=centerX-(sz/2)*2; +% X2=centerX+(sz/2)*2; +% Y1=centerY-(sz/2); +% Y2=centerY+(sz/2); +% image([X2, X1],[Y2, Y1],(im0/255)*64) +% end +colormap('gray') +title('MDS map') + +saveas(hF,[out_root,corrType,sprintf('Corr_%s_MDS_%s.png', input, stimset)]) \ No newline at end of file diff --git a/matlab/PasteImageIntoBackgroundWithGivenDimensions.m~ b/matlab/PasteImageIntoBackgroundWithGivenDimensions.m~ deleted file mode 100644 index 258b4b4..0000000 --- a/matlab/PasteImageIntoBackgroundWithGivenDimensions.m~ +++ /dev/null @@ -1,74 +0,0 @@ -% ������������������������������������������������������������������� -% -% PasteImageIntoBackground_call -% -% ������������������������������������������������������������������� -% -% -% Place an image in the center of a user defined black background -% -% INPUTS: -% -% 1) img: image (bitmap) -% 2) Nrows_bck: # of rows in the background -% 3) Ncols_bck: # of cols in the background -% -% Author: davide -% -% ������������������������������������������������������������������� - -function [img_new] = PasteImageIntoBackground_call( img, Nrows_bck, Ncols_bck ) - -% disp( '... in PasteImageIntoBackground_call' ); - -[im_rows im_cols] = size(img); -disp(['Image size = (', num2str(im_rows), 'x', num2str(im_cols), ')']); - -% Sanity check on the background dimensions -if im_rows > Nrows_bck | im_cols > Ncols_bck - disp(['ERROR! the size of the background is smaller than the size of the image (', ... - num2str(im_rows), 'x', num2str(im_cols), ')']); - return; -end; - -% if the # of rows (columns) in the image is even, so must be the # of rows -% (colums) in the background (to place the image exactly in the middle) -% if rem(im_rows,2) == 0 -% if rem(Nrows_bck,2) ~= 0 -% Nrows_bck = Nrows_bck+1; -% disp(['NOTE: the # of rows of the background was increased of 1. It is now = ', num2str(Nrows_bck)]); -% end; -% else -% if rem(Nrows_bck,2) == 0 -% Nrows_bck = Nrows_bck+1; -% disp(['NOTE: the # of rows of the background was increased of 1. It is now = ', num2str(Nrows_bck)]); -% end; -% end; -% if rem(im_cols,2) == 0 -% if rem(Ncols_bck,2) ~= 0 -% Ncols_bck = Ncols_bck+1; -% disp(['NOTE: the # of columns of the background was increased of 1. It is now = ', num2str(Ncols_bck)]); -% end; -% else -% if rem(Ncols_bck,2) == 0 -% Ncols_bck = Ncols_bck+1; -% disp(['NOTE: the # of columns of the background was increased of 1. It is now = ', num2str(Ncols_bck)]); -% end; -% end; - -% Create background and add image in its center -img_new = zeros( Nrows_bck, Ncols_bck ); -img_new = uint8(img_new); -D_rows = Nrows_bck - im_rows; -D_cols = Ncols_bck - im_cols; -% img_new( ceil(D_rows/2+1):ceil(D_rows/2+im_rows), D_cols/2+1:D_cols/2+im_cols ) = img; -img_new( found(D_rows/2+1):round(D_rows/2+im_rows, D_cols/2+1:D_cols/2+im_cols ) = img; - - -% figure; -% imshow(img_new); -% -% disp( '... END of PasteImageIntoBackground_call' ); - - - diff --git a/matlab/ResizeBlobRatStims_General_morphs.m b/matlab/ResizeBlobRatStims_General_morphs.m index b5241fc..81a311b 100644 --- a/matlab/ResizeBlobRatStims_General_morphs.m +++ b/matlab/ResizeBlobRatStims_General_morphs.m @@ -36,7 +36,7 @@ function ResizeBlobRatStims_General(fnames, imdir, outdir) if mod(IdxImg, 100) == 0 sprintf('Loading image: %s', fnames{IdxImg}) end - + % Load image at right viewpoint Image2Load = [imdir, fnames{IdxImg}]; [img map] = imread( Image2Load ); @@ -173,8 +173,8 @@ function ResizeBlobRatStims_General(fnames, imdir, outdir) OutName = [outdir, fnames{Stim}] imwrite( img_tr, OutName, 'png' ); - imshow(img_tr); - drawnow; + %imshow(img_tr); + %drawnow; % end; %for v_x % end; %for v_y diff --git a/matlab/batch_convert_pov.m b/matlab/batch_convert_pov.m index c1712ae..3844cd1 100644 --- a/matlab/batch_convert_pov.m +++ b/matlab/batch_convert_pov.m @@ -1,11 +1,11 @@ clear all close all -source_root='/media/nas/volume1/behavior/stimuli/pnas_morphs/POV/pov20/im/'; -gray_root='/media/nas/volume1/behavior/stimuli/pnas_morphs/POV/pov20/gray/'; -size_root='/media/nas/volume1/behavior/stimuli/pnas_morphs/POV/pov20/crop/'; +source_root='/media/nas/volume1/behavior/stimuli/pnas_morphs/POV/pov2000/im/'; +gray_root='/media/nas/volume1/behavior/stimuli/pnas_morphs/POV/pov2000/gray/'; +size_root='/media/nas/volume1/behavior/stimuli/pnas_morphs/POV/pov2000/crop/'; -final_root='/media/nas/volume1/behavior/stimuli/pnas_morphs/POV/pov20/final/'; +final_root='/media/nas/volume1/behavior/stimuli/pnas_morphs/POV/pov2000/final/'; %% % Convert to grayscale: @@ -196,8 +196,8 @@ OutName = [final_root, fnames{Stim}] imwrite( img_tr, OutName, 'png' ); - imshow(img_tr); - drawnow; + %imshow(img_tr); + %rawnow; end; %for Stim diff --git a/modules/correlation/build/lib/correlation.py b/modules/correlation/build/lib/correlation.py index a6f64be..7a79043 100644 --- a/modules/correlation/build/lib/correlation.py +++ b/modules/correlation/build/lib/correlation.py @@ -355,7 +355,7 @@ def get_sampled_morphs(imdirectory, outdirectory, nmorphs=20, fixedref=True, ext morph_sample_paths = [os.path.join(imdirectory, fmorphs[midx]) for midx in morph_sample_idxs] - if save_samples is True: + if save_samples: if not os.path.exists(outdirectory): os.makedirs(outdirectory) diff --git a/modules/correlation/correlation.py b/modules/correlation/correlation.py index a6f64be..7a79043 100644 --- a/modules/correlation/correlation.py +++ b/modules/correlation/correlation.py @@ -355,7 +355,7 @@ def get_sampled_morphs(imdirectory, outdirectory, nmorphs=20, fixedref=True, ext morph_sample_paths = [os.path.join(imdirectory, fmorphs[midx]) for midx in morph_sample_idxs] - if save_samples is True: + if save_samples: if not os.path.exists(outdirectory): os.makedirs(outdirectory) diff --git a/modules/euclid/build/lib/euclid.py b/modules/euclid/build/lib/euclid.py index 6d7254f..a2213eb 100644 --- a/modules/euclid/build/lib/euclid.py +++ b/modules/euclid/build/lib/euclid.py @@ -171,7 +171,7 @@ def get_even_dists_euclidean(imdirectory, outdirectory, npoints, fixedref=False, print x, all_impaths[x] morphseq = [all_impaths[int(x)] for x in morphids] - if save_samples is True: + if save_samples: if not os.path.exists(outdirectory): os.makedirs(outdirectory) diff --git a/modules/euclid/euclid.py b/modules/euclid/euclid.py index 6d7254f..a2213eb 100644 --- a/modules/euclid/euclid.py +++ b/modules/euclid/euclid.py @@ -171,7 +171,7 @@ def get_even_dists_euclidean(imdirectory, outdirectory, npoints, fixedref=False, print x, all_impaths[x] morphseq = [all_impaths[int(x)] for x in morphids] - if save_samples is True: + if save_samples: if not os.path.exists(outdirectory): os.makedirs(outdirectory) diff --git a/modules/projection/build/lib/projection.py b/modules/projection/build/lib/projection.py index 841a544..eaed825 100644 --- a/modules/projection/build/lib/projection.py +++ b/modules/projection/build/lib/projection.py @@ -262,11 +262,14 @@ def get_projected_morphs(nmorphs, imdirectory, outdirectory, ext='.png', save_sa morph_sample_paths = [os.path.join(imdirectory, fmorphs[midx]) for midx in morph_sample_idx] - if save_samples is True: + print "SAVE?? ", save_samples + if save_samples: + print 'TRUE' if not os.path.exists(outdirectory): os.makedirs(outdirectory) for m in morph_sample_paths: + print m copy_file(m, outdirectory) morph_list = sorted([f for f in os.listdir(outdirectory) if f.endswith(ext)],key=key_func) @@ -276,6 +279,8 @@ def get_projected_morphs(nmorphs, imdirectory, outdirectory, ext='.png', save_sa morphname = os.path.join(outdirectory,morphname) os.rename(morphname, morphname.replace(old, str(midx))) + print "New sampled morphs saved to: ", outdirectory + return projections, idxs def run(): diff --git a/modules/projection/projection.py b/modules/projection/projection.py index 841a544..eaed825 100644 --- a/modules/projection/projection.py +++ b/modules/projection/projection.py @@ -262,11 +262,14 @@ def get_projected_morphs(nmorphs, imdirectory, outdirectory, ext='.png', save_sa morph_sample_paths = [os.path.join(imdirectory, fmorphs[midx]) for midx in morph_sample_idx] - if save_samples is True: + print "SAVE?? ", save_samples + if save_samples: + print 'TRUE' if not os.path.exists(outdirectory): os.makedirs(outdirectory) for m in morph_sample_paths: + print m copy_file(m, outdirectory) morph_list = sorted([f for f in os.listdir(outdirectory) if f.endswith(ext)],key=key_func) @@ -276,6 +279,8 @@ def get_projected_morphs(nmorphs, imdirectory, outdirectory, ext='.png', save_sa morphname = os.path.join(outdirectory,morphname) os.rename(morphname, morphname.replace(old, str(midx))) + print "New sampled morphs saved to: ", outdirectory + return projections, idxs def run(): diff --git a/sample_morphs.py b/sample_morphs.py index 97df0eb..7af0d31 100644 --- a/sample_morphs.py +++ b/sample_morphs.py @@ -91,6 +91,9 @@ def key_func(afilename): print "Using scalar projection..." projs, idxs = proj.get_projected_morphs(nmorphs, imdirectory, outdirectory, im_format, save_samples) + + print "DID IT" + proj.plot_all_projections(outdirectory, projs, idxs, im_format, show_plot=plot) proj.plot_sampled_projections(outdirectory, idxs, im_format, show_plot=plot) # if plot: