Azzera filtri
Azzera filtri

Reading images from a folder when a particular condition holds true

1 visualizzazione (ultimi 30 giorni)
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 Commenti
shru s
shru s il 7 Giu 2017
Modificato: shru s il 7 Giu 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?

Accedi per commentare.

Risposte (1)

KSSV
KSSV il 7 Giu 2017
Modificato: KSSV il 7 Giu 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 Commenti
shru s
shru s il 7 Giu 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

Accedi per commentare.

Categorie

Scopri di più su Image Processing and Computer Vision in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by