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

Thread Subject:
batch processing

Subject: batch processing

From: Student

Date: 21 Apr, 2012 12:06:08

Message: 1 of 2

Hi I am trying to do some batch processing. I can print all images in a folder to the screen by using :

files = dir('*.png');
num_files = numel(files);
images = cell(1, num_files)
for k = 1:num_files
    images{k} = imread(files(k).name);
    figure, imshow (images{k})
end

But I start running into problems when I try to chnge the images to the red channel, do adaptive histogram equalization an then finally edge detect them. I am trying to print only the final edge detected image of each image. This is the code I created:

files = dir('*.png');
num_files = numel(files);
images = cell(1, num_files)
for k = 1:num_files
    images{k} = imread(files(k).name);

RedChannel= images{k}(:, :, 2);
RedChannel= adapthisteq(RedChannel,'clipLimit',0.01,'Distribution','uniform');
BW = edge(RedChannel, 'canny',.35);
    figure, imshow (BW )
end


Using this code only the first image prints to screen so I am making a mistake somwhere. Can anyone see where I am making the mistake?

Cheers Guys

Subject: batch processing

From: ImageAnalyst

Date: 21 Apr, 2012 16:05:57

Message: 2 of 2

Do you need to store all the images in a cell array? I would think
not. Do you need to have separate figures for each image? I would
think not. Did you use drawnow to force it to update immediately? It
looks like not. I would try this:

try % Start of try/catch block.
    folder = pwd; % Assume files live in the current folder.
    files = dir(fullfile(folder, '*.png'));
    numberOfFiles = length(files);
    figure;
    for k = 1 : numberOfFiles
        fullFileName = fullfile(folder, files(k).name);
        thisImage = imread(fullFileName );
        RedChannel = thisImage(:, :, 2);
        RedChannel = adapthisteq(RedChannel,...
            'clipLimit', 0.01, 'Distribution', 'uniform');
        edgeImage = edge(RedChannel, 'canny', 0.35);
        imshow(edgeImage, []);
        drawnow; % Force it to display immediately.
    end
catch ME
errorMessage = sprintf('Error in function blah_blah_blah().\n\nError
Message:\n%s', ME.message);
fprintf(1, '%s\n', errorMessage);
uiwait(warndlg(errorMessage));
end

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us