フィルターのクリア

Reading images from a folder when a particular condition holds true

1 回表示 (過去 30 日間)
shru s
shru s 2017 年 6 月 7 日
コメント済み: shru s 2017 年 6 月 7 日
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 件のコメント
KSSV
KSSV 2017 年 6 月 7 日
What problem you face with the above code?
shru s
shru s 2017 年 6 月 7 日
編集済み: shru s 2017 年 6 月 7 日
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?

サインインしてコメントする。

回答 (1 件)

KSSV
KSSV 2017 年 6 月 7 日
編集済み: KSSV 2017 年 6 月 7 日
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 件のコメント
KSSV
KSSV 2017 年 6 月 7 日
What error? It is not showing any error here..
shru s
shru s 2017 年 6 月 7 日
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

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeImage Processing and Computer Vision についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by