0
[fname1 path] = uigetfile('*.*','open image file');%*.*
[path,name,ext,ver] = fileparts(fname1);
handles.fname = strcat(name,ext);
a = imread(handles.fname);
r = imresize(a,[256,256]);
file = 'C:\Main CBIR\query images\r.bmp';
[fname,map] = rgb2ind(r,32);
imwrite(fname,map,file);

Above code saves image(BMP) with name r in specified path/folder. But how to save image with its own name? I mean if i input image with name rose.jpg how to save rose.bmp using above code? instead above code saves image with r.bmp. How can i go for it?

1 Answer 1

2

You have the file name (e.g., 'rose') stored in variable name returned from fileparts. you can use it to create the new file name:

file = fullfile( 'c:', 'Main CBIR', 'query images', [name, '.bmp'] );
3
  • Thank you, however if i use imread after imwrite(fname,map,file); command in above code I"m getting an error. imwrite(fname,map,file); b = imread(fname); i got an error like ??? Error using ==> strfind Input strings must have one row. Error in ==> imread at 329 if (strfind(filename, '://')) Error in ==> CBIR_MJP>insert_Callback at 97 b = imread(fname); Y this error?
    – Chethan
    Commented Jun 13, 2013 at 7:43
  • you need to get your code straight. name is a string so is file. However, fname is NOT a string and cannot be used as an input to imread. Try imread( file );
    – Shai
    Commented Jun 13, 2013 at 7:46
  • imread(file) also results in error. ??? Error using ==> ``fileparts at 17 Input must be a row vector of characters. Error in ==> Pre_processing>Pre_processing_OpeningFcn at 60 [path,name,ext,ver] = fileparts(fname); Error in ==> gui_mainfcn at 221 feval(gui_State.gui_OpeningFcn, gui_hFigure, [], ``guidata(gui_hFigure), varargin{:}); file just contains bmp image i think, after this command I'm converting to index as you can see in my code just above imwrite. But i want to read that image which is get saved in specified folder.
    – Chethan
    Commented Jun 13, 2013 at 7:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.