Filter löschen
Filter löschen

Reading images from a folder when a particular condition holds true

1 Ansicht (letzte 30 Tage)
shru s
shru s am 7 Jun. 2017
Kommentiert: shru s am 7 Jun. 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 Kommentare
KSSV
KSSV am 7 Jun. 2017
What problem you face with the above code?
shru s
shru s am 7 Jun. 2017
Bearbeitet: shru s am 7 Jun. 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?

Melden Sie sich an, um zu kommentieren.

Antworten (1)

KSSV
KSSV am 7 Jun. 2017
Bearbeitet: KSSV am 7 Jun. 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 Kommentare
KSSV
KSSV am 7 Jun. 2017
What error? It is not showing any error here..
shru s
shru s am 7 Jun. 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

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Image Processing and Computer Vision finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by