0% found this document useful (0 votes)
14 views7 pages

Thesis AppendixG

Appendix G presents all MATLAB codes written for post processing images. The first six codes are used to process Mie scattering images. Final code, 'processJ.m,' is used to process schlieren images.

Uploaded by

Hani Harashi
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views7 pages

Thesis AppendixG

Appendix G presents all MATLAB codes written for post processing images. The first six codes are used to process Mie scattering images. Final code, 'processJ.m,' is used to process schlieren images.

Uploaded by

Hani Harashi
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

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. end
28. end
29. end
30. end
31. end
32. filename3=strcat('C:\Documents and Settings\
AdamNorberg\Desktop\H2Project\Images\Joe\J_4_10_06\
Phi_040\Final\Final_',b,'.tiff');
33. imwrite(overlap,filename3,'tiff','Colorspace','rgb'
,'Compression','none');
34. disp(strcat('File ',b,' processed'));
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. functionoutput=contour_design(filename,
regions,display,count,mono)
2. %Flow visualization image converter
3. %Adam Norberg, 4/5/2006
4. %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
5.
6. %Input the number of contours and compute contour sizes
7. region_size=1.0/regions;
8.
9. %Use the greatest and least intense pixels to rescale the
image to use the full intensity range 0-255
10. mono_size=size(mono);
11. min_intensity=255;
12. max_intensity=0;
13. for m=1:mono_size(1)
14. for n=1:mono_size(2)
15. if mono(m,n)<min_intensity
16. min_intensity=mono(m,n);
17. end
18. if mono(m,n)>max_intensity
19. max_intensity=mono(m,n);
20. end
21. end
22. end
23. clear m n
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. for c=1:3
43. contouplotr(a,b,c)=0;
%Initialize contour to be full of zeros
44. end
45. end
46. end
47. clear a b
48.
49. %Establish intensity bins for each contour
50. bin(1)=0.0;
51. for k=2:regions+1
52. bin(k)=bin(k-1)+region_size;
53. end
54. bin(regions+1)=1.1;
55. clear k
56. %Divide the concentration array into bins and generate
respective rgb
57. %colors px by px
58. for i=1:con_size(1)
59. for j=1:con_size(2)
60. if concentration(i,j)<=0.25
61. test=0;
62. m=1;
63. while test==0
64. if concentration(i,j)>=bin(m) &
concentration(i,j)<bin(m+1)
65. contourplot(i,j,1)=0;
66. contourplot(i,j,2)=(bin(m)*4);
67. contourplot(i,j,3)=1;
68. test=1;
69. end
70. m=m+1;
71. end
72. end
73. if concentration(i,j)>0.25 & concentration(i,j)<=0.5
74. test=0;
75. m=1;
76. while test==0
77. if concentration(i,j)>=bin(m) &
concentration(i,j)<bin(m+1)
78. contourplot(i,j,1)=0;
79. contourplot(i,j,2)=1;
80. contourplot(i,j,3)=1-((bin(m)-0.25)*4);
81. test=1;
82. end
83. m=m+1;
84. end
85. end
86. if concentration(i,j)>0.5 & concentration(i,j)<=0.75
87. test=0;
88. m=1;
89. while test==0

129
90. if concentration(i,j)>=bin(m) &
concentration(i,j)<bin(m+1)
91. contourplot(i,j,1)=(bin(m)-0.5)*4;
92. contourplot(i,j,2)=1;
93. contourplot(i,j,3)=0;
94. test=1;
95. end
96. m=m+1;
97. end
98. end
99. if concentration(i,j)>0.75 & concentration(i,j)<=1.00
100. test=0;
101. m=1;
102. while test==0
103. if concentration(i,j)>=bin(m) &
concentration(i,j)<=bin(m+1)
104. contourplot(i,j,1)=1;
105. contourplot(i,j,2)=1-((bin(m)-0.75)*4);
106. contourplot(i,j,3)=0;
107. test=1;
108. end
109. m=m+1;
110. end
111. end
112. end
[Link]
[Link] i j m test
[Link]=contourplot;
116.
117.%Save the rgb color contour plot to file and display results
[Link]=strcat(filename,'_contour.tiff');
[Link](contourplot,name,'tiff','Colorspace','rgb',
'Compression','none');
[Link] display==1
121. figure(count), imtool(name);
122. title(strcat('Average_',char(count)));
[Link]
[Link]('contour_design complete');

130
cut.m

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

scale.m

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

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

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

132

You might also like