Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

How can i modified the name of my output image?

Asked by Simon Dussault on 30 Jan 2013

Hi, i want to know how can i change the name of a image when im saving it in another folder? Im doind some image processing with thresholding and i want to save my image where there's a ROI into a folder with a certain name. Right now, i got 1000 images name "image00000, image00001, ...." and i want to change it to "Frame0, Frame1, Frame 2, ...." Can someone help me please

Here's my code right now:

clear all; close all;

% Go get all my Jpgs in my folder

files=dir('C:\Documents and Settings\sidussault\Bureau\Projet intervention\Image test 3\00020_07_230_000D_D1_(0)_20110503_d\Test\*.jpg');

addpath('C:\Documents and Settings\sidussault\Bureau\Projet intervention\Image test 3\00020_07_230_000D_D1_(0)_20110503_d\Test');

addpath('C:\Documents and Settings\sidussault\Bureau\Projet intervention\Image test 3\00020_07_230_000D_D1_(0)_20110503_d\Test\traiter');

%Batch processing loop

for k=1:numel(files)

img=imread(files(k).name);

img1=imresize(img,[800 800]);

img2=rgb2gray(img1); imgBW=im2bw(img1); mask = imopen(imgBW, strel('Disk',1)); mask1 = imfill(mask,'holes'); [L Ne]= bwlabel(mask1); propied=regionprops(L,'basic');

for n=1:size(propied,1)

rectangle('Position',propied(n).BoundingBox,'EdgeColor','r','LineWidth',2)

end

s=find([propied.Area]>500 & [propied.Area]<1000);

for n=1:size(s,2)

rectangle('Position',propied(s(n)).BoundingBox,'EdgeColor','g','LineWidth',2)

end

output_name=['C:\Documents and Settings\sidussault\Bureau\Projet intervention\Image test 3\00020_07_230_000D_D1_(0)_20110503_d\Test\traiter\' files(k).name];

imwrite(mask1, ['C:\Documents and Settings\sidussault\Bureau\Projet intervention\Image test 3\00020_07_230_000D_D1_(0)_20110503_d\Test\traiter\' files(k).name]);

end

0 Comments

Simon Dussault

Products

No products are associated with this question.

1 Answer

Answer by Image Analyst on 30 Jan 2013
Accepted answer

Use sscanf() to extract the number out of the filename. Then use

newBaseFileName = sprintf('Frame%d', theNumber);
fullFileName = fullfile(theFolder, newBaseFileName);

to create the new filename.

0 Comments

Image Analyst

Contact us