Merge branch 'master' of https://whale.am28.uni-tuebingen.de/git/teaching/scientificComputing
This commit is contained in:
		
						commit
						77ad5ed068
					
				
							
								
								
									
										31
									
								
								projects/project_pca_natural_images/solution/ConeResponse.m
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										31
									
								
								projects/project_pca_natural_images/solution/ConeResponse.m
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,31 @@ | ||||
| function Y = ConeResponse(X) | ||||
| 
 | ||||
| wl_r = 700; | ||||
| wl_g = 510; | ||||
| wl_b = 440; | ||||
| wl = [wl_r; wl_g; wl_b]; | ||||
| 
 | ||||
| mu_s = 445; | ||||
| mu_m = 545; | ||||
| mu_l = 575; | ||||
| 
 | ||||
| sig_s = 20; | ||||
| sig_m = 40; | ||||
| sig_l = 45; | ||||
| 
 | ||||
| s = gauss(wl,mu_s,sig_s)/gauss(mu_s,mu_s,sig_s); | ||||
| m = gauss(wl,mu_m,sig_m)/gauss(mu_m,mu_m,sig_m); | ||||
| l = gauss(wl,mu_l,sig_l)/gauss(mu_l,mu_l,sig_l); | ||||
| 
 | ||||
| S = X'*s; | ||||
| M = X'*m; | ||||
| L = X'*l; | ||||
| 
 | ||||
| Y = [L, M, S]'; | ||||
| %  | ||||
| % close all | ||||
| % hold on | ||||
| % plot(lam,s,'b') | ||||
| % plot(lam,m,'g') | ||||
| % plot(lam,l,'r') | ||||
| % hold off | ||||
							
								
								
									
										3
									
								
								projects/project_pca_natural_images/solution/gauss.m
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								projects/project_pca_natural_images/solution/gauss.m
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,3 @@ | ||||
| function Y = gauss(X,mu,sigma) | ||||
| Y = exp(-0.5*((X-mu)/sigma).^2)./sqrt(2*pi*sigma^2); | ||||
| % Y = Y/exp(-0.5*(mu/sigma).^2)./sqrt(2*pi*sigma^2); | ||||
							
								
								
									
										65
									
								
								projects/project_pca_natural_images/solution/main.m
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										65
									
								
								projects/project_pca_natural_images/solution/main.m
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,65 @@ | ||||
| clear all | ||||
| close all | ||||
| pic = imread('D:\Dokumente\MATLAB\Matlabkurs2018\pca\natimg.jpg'); | ||||
| pic = pic(end:-1:1,:,:); | ||||
| 
 | ||||
| red   = double(pic(:,:,1)); | ||||
| green = double(pic(:,:,2)); | ||||
| blue  = double(pic(:,:,3)); | ||||
| % mat = [red(:),green(:),blue(:)]; | ||||
| 
 | ||||
| mat = reshape(double(pic),size(pic,1)*size(pic,2),size(pic,3))'; | ||||
| cones = ConeResponse(mat); | ||||
| % [coeff, score, latent] = pca(mat,'Centered',false); | ||||
| % [coeff, score, latent] = pca(cones,'Centered',false); | ||||
| 
 | ||||
| % n = 10000; | ||||
| % cones = cones(:,randi([1,size(cones,2)],1,n)); | ||||
| cones = mat; | ||||
| cv = cov(cones'); | ||||
| [ev, ew] = eig(cv); | ||||
| [ew, ew_idx] = sort(diag(ew), 'descend'); | ||||
| coeff = cones'*ev(:,ew_idx); | ||||
| % coeff = [coeff'; zeros(size(pic,1)*size(pic,2)-size(coeff,2),3)]; | ||||
| 
 | ||||
| 
 | ||||
| c1 = reshape(coeff(:,1),size(pic,1),size(pic,2)); | ||||
| c2 = reshape(coeff(:,2),size(pic,1),size(pic,2)); | ||||
| c3 = reshape(coeff(:,3),size(pic,1),size(pic,2)); | ||||
| 
 | ||||
| % score | ||||
| 
 | ||||
| figure | ||||
| subplot(221) | ||||
| contourf(red) | ||||
| axis('square') | ||||
| 
 | ||||
| subplot(222) | ||||
| contourf(green) | ||||
| axis('square') | ||||
| 
 | ||||
| subplot(223) | ||||
| contourf(blue) | ||||
| axis('square') | ||||
| colormap('gray') | ||||
| 
 | ||||
| subplot(224) | ||||
| imshow('D:\Dokumente\MATLAB\Matlabkurs2018\pca\natimg.jpg') | ||||
| axis('square') | ||||
| 
 | ||||
| figure | ||||
| subplot(221) | ||||
| contourf(c1) | ||||
| axis('square') | ||||
| 
 | ||||
| subplot(222) | ||||
| contourf(c2) | ||||
| axis('square') | ||||
| colormap('gray') | ||||
| 
 | ||||
| subplot(223) | ||||
| contourf(c3) | ||||
| axis('square') | ||||
| colormap('gray') | ||||
| 
 | ||||
| % score | ||||
		Reference in New Issue
	
	Block a user