[OT] $DISPLAY screwing up with EPS when matlab run in background?

From: H. S. (greatexcalibur_at_yahoo.com)
Date: 04/29/05

  • Next message: a.list.address_at_gmail.com: "Re: kscreensaver problem"
    To: debian-user@lists.debian.org
    Date: Fri, 29 Apr 2005 00:49:48 -0400
    
    

    (I posted this in comp.soft-sys.matlab but got no response, so I am
    trying my luck here)

    Hi,

    (matlab version: (version 6.5.1.199709 (R13) Service Pack 1) )
    I am trying to run a matlab function I wrote in the background. The
    function plots the color histogram of a given image, opens the plot
    window and prints out the figure to an EPS file. When I run the function
    from within a matlab session, everything works fine. But when I run it
    in background, problem arises in the eps file generated.

    I have a bunch of images to make histograms of. So I wrote a shell
    script which calls matlab in the background and runs the function over
    all the images. However, I do not get a proper EPS file. The resulting
    file is just tiny little white square. The output file of the background
    session does not report any errors.

    Here is the shell script I am using (only one image file is used below,
    but I will eventually use a for-do-done statement to go over all the images)
    #############################################################
    #!/bin/bash -f

    # Clear the DISPLAY.
    #unset DISPLAY # unset DISPLAY for some shells

    # Call MATLAB with the appropriate input and output,
    # make it immune to hangups and quits using ''nohup'',
    # and run it in the background.
    IMG="girl1.png"
    MFUNC="colorhistplot('girl1.png')"
    nohup matlab -nodisplay -nodesktop -nosplash -r $MFUNC > script.out &
    #############################################################

    And here is the matlab function that I wrote(The function works for a
    color PNG file. Can be called as colorhistplot('imgfile.png')):
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    function OutArgs=colorhistplot(ImgFile)

    %colorhistplot('Img.ppm') Plot color histogram of the specified image file
    %
    % Img.ppm Filename of the image Img.ppm. Output is
    Img.eps.
    %
    %
    %
    %This function plots the color histogram of the specified file. The
    output is
    %fixed so that the EPS exported can be included in a Word or LaTeX document
    %
    % Example, call the function in matlab with the following command:
    % colorhistplot('myimg.ppm')
    %where myimg.ppm is the color image whose histogram is desired. The
    output is
    %is an EPS file of the same basename as the input image file but with the
    %extension ".eps".

    %first read the image file data into a matrix
       I = imread(ImgFile);

    if (size(I, 3) ~= 3)
         error('rgbhist:numberOfSamples', 'Input image must be RGB.')
    end

    nBins = 256;

    rHist = imhist(I(:,:,1), nBins);
    gHist = imhist(I(:,:,2), nBins);
    bHist = imhist(I(:,:,3), nBins);

    hFig = figure;
    figure(hFig);

    subplot(1,3,1); hr = bar(0:255, rHist,'r');
    %xlabel('i','FontName','Helvetica','FontSize',9);
    set(gca,'FontSize',6);axis tight;legend('Red');legend(gca,'boxoff');
    ylabel('n','FontName','Helvetica','FontSize',8);

    subplot(1,3,2); hg = bar(0:255, gHist,'g');
    %ylabel('n','FontName','Helvetica','FontSize',8);
    set(gca,'FontSize',6);axis tight;legend('Green');legend(gca,'boxoff');
    xlabel('i','FontName','Helvetica','FontSize',9);set(gca,'FontSize',6);axis
    tight

    subplot(1,3,3); hb = bar(0:255, bHist,'b');
    %xlabel('i','FontName','Helvetica','FontSize',9);
    set(gca,'FontSize',6);axis tight;legend('Blue');legend(gca,'boxoff');
    %ylabel('n','FontName','Helvetica','FontSize',8);

    %before printing the figure to a file, makeup a filename
    %first, find the index where the dot and extension (e.g. .png) starts
    ExtInd=regexpi(ImgFile,'\.[a-zA-Z][a-zA-Z][a-zA-Z]$');
    %get the basename of the file (without the extension)
    BaseName=ImgFile(1:ExtInd-1);
    %now make the actual output filename (with the .eps extension)
    OutFileName=strcat(BaseName,'.eps')

          set(gcf,'PaperUnits','centimeters','PaperPosition',[0.5 0.5 18.5
    5.5]);

    %now print the figure to EPS figure.
    print(gcf,'-depsc2','-r600',OutFileName)
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

    Any idea what is going wrong when the shell script is run? Does this
    have anything to do with a matlab plot window being open when the print
    command is to be given?

    thanks,
    ->HS

    -- 
    Please remove the underscores ( the '_' symbols) from my email address 
    to obtain the correct one. Apologies, but the fudging is to remove spam.
    -- 
    To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org 
    with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
    

  • Next message: a.list.address_at_gmail.com: "Re: kscreensaver problem"

    Relevant Pages

    • Re: eps picture encoding under linux
      ... I'm running matlab under Linux (I've tried several matlab versions ... linux distributions as well). ... but when printing it in an eps file with File-Save as or with the ... This might come from an encoding problem, ...
      (comp.soft-sys.matlab)
    • Re: EXPORT FIGURE TO EPS
      ... I tried to include an eps file (exported from MATLAB figure) into ... This MATLAB figure was a high resolution one, ... Why is the quality of the pdf file produced by the LATEX with the ...
      (comp.soft-sys.matlab)
    • why my eps becomes blurry in final pdf
      ... Matlab and display the result as a truecolor image specified by RGB; ... the image in the final pdf document is blurry. ... MxN matrix) and use Matlab to produce the eps file, ...
      (comp.text.tex)
    • Re: EXPORT FIGURE TO EPS
      ... I tried to include an eps file (exported from MATLAB figure) into ... This MATLAB figure was a high resolution one, ... Why is the quality of the pdf file produced by the LATEX with the ...
      (comp.soft-sys.matlab)
    • Re: Nyquist by hand
      ... everyone has at least a student version of Matlab available. ... Nyquist plots with a calculator and graph paper. ... cough up a Nyquist plot then you will doing three or four Nyquist plots ... Bode plot can be done with experimental data and any uniform gain is ...
      (sci.engr.control)