Image analysis with 688x520 images works, but same program produces nonsense for 1101x832 images

Hi, I wrote a matlab program for the analysis of a folder full of images (all identical size and format). I load all images and then process them one after the other in a for loop. For 688x520 pxls images everything works well, but when I apply the program on 1101x832 pxls images, it returns different values than when I load every image individually (without the loop). Here is my code:
folder='D:\...';
%read in all images from folder
filePattern = fullfile(folder, '*.bmp');
bmpfiles=dir(filePattern);
numfiles=length(bmpfiles);
for i=1:numfiles
a{i}=importdata(bmpfiles(i).name);
end
for i=1:numfiles
% convert to gray scale
a_gray=rgb2gray(a{i});
% Rest of the image analysis
%...
%...
end;

5 commentaires

Silke - can you elaborate on what you mean by produces nonsense and it returns different values? Do you call the image analysis code on an individual grayscale image (so you have done the conversion with rgb2gray) or do you do it some other way?
Try stepping through the code by putting a breakpoint at the line a_gray=rgb2gray(a{i});. What are the dimensions of a_gray? Does it make sense?
Hi Geoff, when I developed the program, I ran it for individual images with the aim of obtaining a value that describes the size of an object in the image. When I was pleased with the result, I created the loop so I get the size of the object in every image in the folder. This worked for the smaller images (I still got the same result for the individual images), but when I tried it on the bigger images the results didin't agree anymore. Can you follow me? I do the image analysis on each individual image (convert it to grayscale first, then do the analysis). The dimensions of a_gray do make sense. Any other ideas?
There must be a problem with your image analysis function. Is there some dependency on the smaller image dimensions? In the larger images, is the object that you are trying to size bigger, smaller, or the same size as in the original image? Does the nonsense values give you a size that is bigger or smaller than the actual size of the image, and is this consistent across all of the larger images?
But then you are saying that if you run the code on a single large image it works fine. Is this correct? What happens if you run the function on another large image - is the object size correct or not?
Yeah, that's the funny thing about it, everything works just fine on single images, but not in the loop. I noticed that something is going wrong as every twelfth object size was smaller than the others by about 10% although the object size shouldn't (or only marginally) change. That's when I had a closer look and noticed that all the values (apart from the very first one) differed. What is the function Shan? Sorry, I couldn't find it anywhere... Thanks for your help, Geoff, very much appreciated!!
Shan was a typo. If you are convinced that your code works for all single images, then you may need to post more of your code. Also, how do you call the processing on a single image? Do you gave a separate function for this?

Connectez-vous pour commenter.

Réponses (1)

Maybe there are some variables set from your first analysis. Use
clear
and rerun your second analysis.

1 commentaire

Hi Thorsten, thanks for the tipp. I cleared the variable for the image with clearvars, but unfortunately there was no change... Any other ideas?

Connectez-vous pour commenter.

Question posée :

le 17 Déc 2014

Commenté :

le 18 Déc 2014

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by