Some years ago I wrote a script to take output images from the Arbitrary Transmission Line Calculator (ATLC) and convert them to quantitave contour plots. This is work I did with Scott Jones, David Robinson and Mark Blonquist. I am starting to remember more of that work. I will keep a copy here for reference
- function [OUTPUT,vals]=bin_to_contour_rowsplit(pixel_width,pixel_height,width_in_meters,height_in_meters,num_contours,filename,percent_lim,split)
- %This MAtlab function was created by:
- % Seth Humphries 10-MAY-2004
- % It if for use with the ATLC program and it imports the binary data that ATLC generates,
- % and creates a contour plot of this data.
- %
- %NOTE: for large values of pixel_height and pixel_width this will take a LONG time to process
- %
- %An example of how to call this program from the matlab command prompt is as follows:
- % [outputmatrix,inputvalues]=bin_to_contour(600,600,0.001,0.001,60,'BLAH.U.bin');
- % where BLAH is the name of whatever image process by ATLC, 0.001 is 1mm, and the data is 600 by 600 pixels
- %
- %The following is an explanation of the values input by the user:
- %pixel_width is the width of the original image in pixels
- %pixel_height is the height of the original image in pixels
- %width_in_meters is the physical width of the original image in meters
- %height_in_meters is the physical height of the original image in meters
- % the units of output in the .bin file from ATLC are in joules/(m*pixel^2) those values
- % must be adjusted for the diference in units (should be joules/(m^3) )
- % see conversionH and conversionW (which must be the same for the program to work).
- %
- %num_countours is the number of contours desired by the user.
- % they are in even increments between 100% and 1% of maximum power
- %
- %filename is the file from which to import the data, it must be the .bin output from the ATLC program
- % the extension of filename is altered to .dat and "_Xpercent" (where X is percent_lim) is added to the end of the name.
- % The data is exported as comma seperated values so that the data may be read into other
- % programs such as excel, sigma plot, etc. At the top of the data file statistic values from the
- % data are placed for the user's information
-
- percent=percent_lim/100;
- %read in the binary data
- average=1;
- area=1;
-
- %find the conversion factor
- conversionH=height_in_meters/pixel_height;
- conversionW=width_in_meters/pixel_width;
-
- %verify that the factor is the same in both directions and if so apply it to the matrix
- if (conversionW == conversionH)
- conversionH=1/conversionW;
- average=conversionH;
- area=conversionH;
- else
- % error=['The height conversion factor is not the same';'as the width conversion factor. The contour ';'plot is not adjusted for units ';]
- error=['The height conversion factor is not the same as the width conversion factor. The contour plot is not adjusted for units ']
- end;
-
- %convert the data from a vector to a matrix of dimensions "pixel_height by pixel_width"
- one=maximum*percent;
- row=1;col=1;q=1;r=1;
- for (i=1:Asize);
- count=count+1;
- p=p+1;
- if (row >=split)
- q=q+1;
- else
- r=r+1;
- end;
- end;
- end;
- if (col == pixel_width)
- end;
- end;
- average=average*sum/count; %average is either 1 or conversionH
-
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% this part of the function calculates how to adjust the
- % axes of the figure to fit the 1percent contour nicely on the plot
- % ymin=0;ymax=0;xmin=0;xmax=0;
- % i=1;j=1;
- % while (ymin == 0 && i<=pixel_width)
- % while (ymin == 0 && j<=pixel_height)
- % if (OUTPUT(i,j) >= one)
- % ymin=i;
- % end;
- % j=j+1;
- % end;
- % j=1;
- % i=i+1;
- % end;
- %
- % i=1;j=1;
- % while (xmin == 0 && j<=pixel_height)
- % while (xmin == 0 && i<=pixel_width)
- % if (OUTPUT(i,j) >= one)
- % xmin=j;
- % end;
- % i=i+1;
- % end;
- % i=1;
- % j=j+1;
- % end;
- %
- % i=pixel_height;j=1;
- % while (ymax == 0 && i>=1)
- % while (ymax == 0 && j<=pixel_height)
- % if (OUTPUT(i,j) >= one)
- % ymax=i;
- % end;
- % j=j+1;
- % end;
- % j=1;
- % i=i-1;
- % end;
- %
- % j=pixel_width;i=1;
- % while (xmax == 0 && j>=1)
- % while (xmax == 0 && i<=pixel_width)
- % if (OUTPUT(i,j) >= one)
- % xmax=j;
- % end;
- % i=i+1;
- % end;
- % i=1;
- % j=j-1;
- % end;
-
- %caculate where to place the contours
- incr=(1/num_contours);
- vals=[percent:incr:1].*maximum;
-
- w=0.05*pixel_width;
- h=0.05*pixel_height;
- %create a new figure and plot a contour on it. It is faster for smaller number of contour lines
- fig_id=figure;
- %to draw, matlab then calculates where to place them.
- %set(gca,'YLim',[ymin-h ymax+h]);
- %set(gca,'XLim',[xmin-w xmax+w]);
- yticks=0:pixel_height/4:pixel_height;
- xticks=0:pixel_width/4:pixel_width;
-
- % title(filename(1:fsize-4));
-
-
- % Output the data to a data file as described below
- % format will be comma seperate values. this takes SOME time
- else
- surf_file=[filename(1:fsize-4),'unbinary',num2str(percent_lim),'percent_rowsplit_for_plotting_in_surfer.dat'];
- end;
-
- fprintf(outID,'\nArea of Pixels greater than %g percent in meter^2 = %g',percent_lim,q/(conversionH*conversionH));
-
- fprintf(outID,'\nArea of Pixels greater than %g percent in meter^2 = %g',percent_lim,r/(conversionH*conversionH));
-
- x_per=100*width_in_meters/pixel_width;%cm
- y_per=100*height_in_meters/pixel_height;
- for (i=1:pixel_height)%rows
- for(j=1:pixel_width)%columns
- if (OUTPUT(i,j) >= one)
- else
- end;
- end;
- end;
-