Path: news.mathworks.com!not-for-mail
From: "ridhi jain" <rivi_jain@yahoo.co.in>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Guide, load image from folder
Date: Mon, 18 May 2009 04:31:01 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 22
Message-ID: <guqoa5$d6p$1@fred.mathworks.com>
References: <ggq8t2$mcg$1@fred.mathworks.com> <ggqa9i$679$1@fred.mathworks.com> <ggqg52$7jo$1@fred.mathworks.com> <ggs8ev$539$1@fred.mathworks.com> <ggt06r$nfm$1@fred.mathworks.com>
Reply-To: "ridhi jain" <rivi_jain@yahoo.co.in>
NNTP-Posting-Host: webapp-02-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1242621061 13529 172.30.248.37 (18 May 2009 04:31:01 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Mon, 18 May 2009 04:31:01 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1833515
Xref: news.mathworks.com comp.soft-sys.matlab:540618


"Image Analyst" <imageanalyst@mailinator.com> wrote in message <ggt06r$nfm$1@fred.mathworks.com>...
> "Rui Gomes" <rpgomes84@gmail.com> wrote in message <ggs8ev$539$1@fred.mathworks.com>...
> ----------------------------------------
> Rui:
> I'm not sure why you chose to not use my code and go with something less robust.  You should have used my code.  The problem with your code is that if the user selects a file that is not in the current working directory, your code will throw an error.  This is because you're totally ignoring the folder, which can get returned as an optional return argument from uigetfile().  You need to use fullfile as I had shown you.  Checking for the user clicking the cancel button is a good idea though.  Here is some robust code that will work for any jpg image (the format you seem to want) located in any folder, and also checks for the user clicking the Cancel button:
> 
> clc;
> [BaseFileName,PathName,FilterIndex] = uigetfile('*.jpg');
> if(BaseFileName ~= 0) 
> 	fullFileName = fullfile(PathName, BaseFileName);
> 	inputImageArray = imread(fullFileName);
> 	image(inputImageArray); 
> 	axis off; 
> end 
> 
> I suggest you use the above code instead of your code - it will be more robust.  I also suggest you use descriptive variable names.  Many MATLAB users also recommend against the use of i as a variable since it indicates a comples number, but since MATLAB is case sensitive, capital I will be okay, just not that descriptive, especially if you plan on having other image variables in your program.
> Regards,
> ImageAnalyst


hi,
the code you suggested above worked really very well for colored images. But when it came to grayscale images the image that appeared on the axes was red in color. Why is it so? How can this code be modified to get the correct image in the axes?