Effacer les filtres
Effacer les filtres

Reading images from a folder when a particular condition holds true

1 vue (au cours des 30 derniers jours)
shru s
shru s le 7 Juin 2017
Commenté : shru s le 7 Juin 2017
Hello, suppose i have a folder containing a set of images. In a for loop, every time condition A is true i want a blank image and every time condition B is true i would like one image from the sequence of images in my folder.
for x=1:c
if (c > 440)
c=1;
figure;
else if (c < 440)
Img = imread(fullfile(folderName, Imgs(j).name));
j=j+1;
end
end
end
This is what i have tried. Can you tell me how its done?
  2 commentaires
KSSV
KSSV le 7 Juin 2017
What problem you face with the above code?
shru s
shru s le 7 Juin 2017
Modifié(e) : shru s le 7 Juin 2017
this is the error message -
Index exceeds matrix dimensions.
Error in program (line 62)
Img = imread(fullfile(folderName, Imgs(j).name));
do u know how i can fix this?

Connectez-vous pour commenter.

Réponses (1)

KSSV
KSSV le 7 Juin 2017
Modifié(e) : KSSV le 7 Juin 2017
It is because..your j is more then the number of images present...you have to break the loop, if j increases.
N = length(Imgs) ;
for x=1:c
if (c > 440)
c=1;
figure;
else if (c < 440)
Img = imread(fullfile(folderName, Imgs(j).name));
j=j+1;
if j >= N
break
end
end
end
end
Note that, there are better ways to do this.
  3 commentaires
KSSV
KSSV le 7 Juin 2017
What error? It is not showing any error here..
shru s
shru s le 7 Juin 2017
close all
img1=imread('C:\Users\Shruthi\Desktop\project\A data\is.jpg');
imshow(img1);
figure;
img1=rgb2gray(img1);
imhist(img1);
threshold=120;
binaryImage = img1 < threshold;
figure;
imshow(binaryImage);
image = bwareaopen(binaryImage,30);
% image= ~image;
figure;
imshow(image);
vp=sum(image,1)
hp=sum(image,2);
plot(vp,'b');
figure;
[le , br ] = size(image);
darkpixels=hp<1;
[lableledregions noofregions]= bwlabel(darkpixels);
fprintf('number of regions =%d\n',noofregions);
z=min(vp);
s=find(vp>z)
e=find(vp==z)
letterLocations = vp > z;
d = diff(letterLocations);
startingColumns = find(d>0);
endingColumns = find(d<0);
folderName = 'C:\Users\p\project\A data\SegmentedCharacters';
Imgs = dir(fullfile(folderName, '*.jpg'));
y=length(vp');
plot(hp,'r');
c=1;
for j=1:y
if vp(j)==z
c = c + 1;
N = length(Imgs) ;
for x=1:c
if (c > 440)
c=1;
figure;
else if (c < 440)
Img = imread(fullfile(folderName, Imgs(j).name));
j=j+1;
if j >= N
break
end
end
end
end
end
end
this is my entire code

Connectez-vous pour commenter.

Catégories

En savoir plus sur Image Processing and Computer Vision dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by