Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

Appendix G Image Processing MATLAB Codes

Appendix G presents all MATLAB codes written for post processing the Mie scattering and schlieren flow visualization images. The first six codes: compare.m, contour.m, contour_design.m, cut.m, scale.m, and scale2.m are used to process Mie scattering images. The final code, processJ.m is used to process schlieren images.

compare.m
1. for a=1:20 2. if a<=9 3. b=char(a+47); 4. elseif a>9 & a<20 5. b=strcat(char(49),char(a-10+48)); 6. else 7. b=strcat(char(50),char(48)); 8. end 9. filemane=strcat('C:\Documents and Settings\ AdamNorberg\Desktop\H2Project\Images\Joe\Fluent\ Phi_040\plane_',b,'.tiff'); 10. fluent=imread(filemane,'tiff'); 11. filename2=strcat('C:\Documents and Settings\ AdamNorberg\Desktop\H2Project\Images\Joe\J_4_10_06\ Phi_040\test\Average_',b,'_contour.tiff'); 12. flowvis=imread(filename2,'tiff'); 13. size_fluent=size(fluent); 14. size_flowvis=size(flowvis); 15. for k=1:size_fluent(1); 16. for l=1:size_fluent(2); 17. for m=1:size_fluent(3); 18. if l<(260+(4*a)) | l>(948+(4*a)) %l=302, l=988 19. overlap(k,l,m)=fluent(k,l,m); 20. else 21. if k<43 | k>706 22. overlap(k,l,m)=fluent(k,l,m); 23. elseif fluent(k,l,1)>=200 & fluent(k,l,2)>=200 & fluent(k,l,3)>=200 24. overlap(k,l,m)=flowvis(k-42, l-(259+(4*a)),m); %l-301 25. else 26. overlap(k,l,m)=fluent(k,l,m);

126

27. 28. 29. 30. 31. 32.

end end end end end filename3=strcat('C:\Documents and Settings\ AdamNorberg\Desktop\H2Project\Images\Joe\J_4_10_06\ Phi_040\Final\Final_',b,'.tiff'); imwrite(overlap,filename3,'tiff','Colorspace','rgb' ,'Compression','none'); disp(strcat('File ',b,' processed'));

33. 34. 35. end

contour.m
1. function output=contour(number) 2. for a=1:20 3. if a<=9 4. b=char(a+47); 5. elseif a>9 & a<20 6. b=strcat(char(49),char(a-10+48)); 7. else 8. b=strcat(char(50),char(48)); 9. end 10. temp=strcat('C:\Documents and Settings\AdamNorberg\ Desktop\H2Project\Images\Joe\J_4_10_06\Phi_040\ Average_',b); 11. wholename=strcat(temp,'.bmp'); 12. image=imread(wholename,'bmp'); 13. mono=image(:,:,3); 14. mono2=scale(mono); 15. mono3=cut(mono2); 16. mono4=scale2(mono3); 17. temp2=strcat('C:\Documents and Settings\AdamNorberg\ Desktop\H2Project\Images\Joe\J_4_10_06\Phi_040\ test\Average_',b); 18. contour_design(temp2,number,0,a,mono4); 19. disp(strcat('image ',b,' processing complete! :-)')); 20. end 21. output=1;

127

contour_design.m
1. 2. 3. 4. functionoutput=contour_design(filename, regions,display,count,mono) %Flow visualization image converter %Adam Norberg, 4/5/2006 %This program takes a flow vis image and rescales it into contours of smoke "concentration" from 0 to 1.0 and then breaks it up into 'regions' number of full color contours %Input the number of contours and compute contour sizes region_size=1.0/regions; %Use the greatest and least intense pixels to rescale the image to use the full intensity range 0-255 mono_size=size(mono); min_intensity=255; max_intensity=0; for m=1:mono_size(1) for n=1:mono_size(2) if mono(m,n)<min_intensity min_intensity=mono(m,n); end if mono(m,n)>max_intensity max_intensity=mono(m,n); end end end clear m n

5. 6. 7. 8. 9.

10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 22. 23. 24. 25. mono=double(mono); 26. mono_full=(mono-double(min_intensity))*(255.0/(double (max_intensity)-double(min_intensity))); 27. %imtool(int(mono_full)) %Observe mono_full for debug? 28. concentration=mono_full*(1/255); %Monochrome scaled from 0 to 1 29. for m=1:mono_size(1) 30. for n=1:mono_size(2) 31. if concentration(m,n)>=1.0 32. concentration(m,n)=1.0; 33. end 34. end 35. end 36. clear m n 37. 38. %initialize the rgb contour plot px values to 0 39. con_size=size(concentration); %The length and width of concentration 40. for a=1:con_size(1) 41. for b=1:con_size(2)

128

42. 43. 44. 45. 46. 47. 48. 49. 50. 51. 52. 53. 54. 55. 56. 57. 58. 59. 60. 61. 62. 63. 64. 65. 66. 67. 68. 69. 70. 71. 72. 73. 74. 75. 76. 77. 78. 79. 80. 81. 82. 83. 84. 85. 86. 87. 88. 89.

for c=1:3 contouplotr(a,b,c)=0; %Initialize contour to be full of zeros end end end clear a b %Establish intensity bins for each contour bin(1)=0.0; for k=2:regions+1 bin(k)=bin(k-1)+region_size; end bin(regions+1)=1.1; clear k %Divide the concentration array into bins and generate respective rgb %colors px by px for i=1:con_size(1) for j=1:con_size(2) if concentration(i,j)<=0.25 test=0; m=1; while test==0 if concentration(i,j)>=bin(m) & concentration(i,j)<bin(m+1) contourplot(i,j,1)=0; contourplot(i,j,2)=(bin(m)*4); contourplot(i,j,3)=1; test=1; end m=m+1; end end if concentration(i,j)>0.25 & concentration(i,j)<=0.5 test=0; m=1; while test==0 if concentration(i,j)>=bin(m) & concentration(i,j)<bin(m+1) contourplot(i,j,1)=0; contourplot(i,j,2)=1; contourplot(i,j,3)=1-((bin(m)-0.25)*4); test=1; end m=m+1; end end if concentration(i,j)>0.5 & concentration(i,j)<=0.75 test=0; m=1; while test==0

129

90. 91. 92. 93. 94. 95. 96. 97. 98. 99. 100. 101. 102. 103.

if concentration(i,j)>=bin(m) & concentration(i,j)<bin(m+1) contourplot(i,j,1)=(bin(m)-0.5)*4; contourplot(i,j,2)=1; contourplot(i,j,3)=0; test=1; end m=m+1; end end if concentration(i,j)>0.75 & concentration(i,j)<=1.00 test=0; m=1; while test==0 if concentration(i,j)>=bin(m) & concentration(i,j)<=bin(m+1) contourplot(i,j,1)=1; contourplot(i,j,2)=1-((bin(m)-0.75)*4); contourplot(i,j,3)=0; test=1; end m=m+1; end end

104. 105. 106. 107. 108. 109. 110. 111. 112. end 113.end 114.clear i j m test 115.output=contourplot; 116. 117.%Save the rgb color contour plot to file and display results 118.name=strcat(filename,'_contour.tiff'); 119.imwrite(contourplot,name,'tiff','Colorspace','rgb', 'Compression','none'); 120.if display==1 121. figure(count), imtool(name); 122. title(strcat('Average_',char(count))); 123.end 124.disp('contour_design complete');

130

cut.m
1. 2. 3. 4. 5. 6. 7. 8. 9. function output=cut(image) dims=size(image); cutoffpxs=100; for m=1:dims(1) for n=1:(dims(2)-cutoffpxs) output(m,n)=image(m,(n+cutoffpxs)); end end disp('cut complete');

scale.m
1. 2. 3. 4. 5. 6. function output=scale(image) horizontal=768; vertical=490; hnew=horizontal-((horizontal/256)*(256-213)); output=imresize(image,[vertical,hnew]); disp('scale complete');

scale2.m
1. 2. 3. 4. 5. 6. 7. 8. 9. function output=scale2(image) %Fluent images -- 1"=298px %Flow Vis images -- 1"=213px current_size=size(image); new_size(1)=current_size(1)+((current_size(1)/213)*(298-213)); new_size(2)=current_size(2)+((current_size(2)/213)*(298-213)); new_size=new_size; output=imresize(image,[new_size(1),new_size(2)]); disp('scale2 complete');

131

processJ.m
1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 22. 23. 24. 25. 26. 27. 28. 29. 30. 31. 32. 33. 34. 35. 36. 37. 38. 39. 40. 41. 42. function output=processJ(file_extension,display,max) %Schlieren image processing code %This code scales up the image intensity and crops the area of interest %Adam Norberg, 6/21/06 %Assemble entire filename folder=['C:\Documents and Settings\Adam 8.Norberg\ Desktop\H2Project\Schlieren\Nozzle J\']; filename=[folder,'LF_8_Tc_T_Air',file_extension,'.jpg']; %Read the image into Matlab and convert into a grayscale image image=imread(filename); grayimage=rgb2gray(image); %Crop full image down to the area of interest sized_image=imcrop(grayimage,[450 375 1600 1075]); %Use the greatest and least intense pixels to rescale the image to use the %full intensity range 0-255 image_size=size(sized_image); min_intensity=255; max_intensity=0; for m=1:image_size(1) %m corresponds to the x pixel location for n=1:image_size(2) %n corresponds to the y pixel location if grayimage(m,n)<min_intensity min_intensity=sized_image(m,n); end if grayimage(m,n)>max_intensity max_intensity=sized_image(m,n); end end end full_scale=(sized_image-min_intensity)*(max/( max_intensity-min_intensity)); %Write the processed image to file savename=[folder,'Processed\LF_8_Tc_T_Air',file_extension,'.jpg']; imwrite(full_scale,savename,'jpeg','Quality',100); %Display the processed image if display=1 if display==1 imshow(savename); end output=1;

132

You might also like