Image processing toolbox matlab successively analysing few images

The question is how to drive the code for handling multiple images in sequence? for example to choose just 100 images, perform calculations, and enter the results in a table cell? The images are searched and the calculation of a circle of the radius and volume
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
[FileName, PathName]=uigetfile('*.bmp; *.jpg; *.gif', 'Open File');
if FileName~=0
rgb=imread(strcat(PathName, FileName));
I=rgb2gray(rgb);
I=imcrop(I, [320 60 900 900]);
imshow(I);
text(732,501,'…',...
'FontSize',7,'HorizontalAlignment','right')
hy=fspecial('sobel');
hx=hy';
Iy=imfilter(double(I), hy, 'replicate');
Ix=imfilter(double(I), hx, 'replicate');
gradmag=sqrt(Ix.^2+Iy.^2);
L=watershed(gradmag);
Lrgb=label2rgb(L);
se=strel('disk', 20);
Io=imopen(I, se);
Ie=imerode(I, se);
Iobr=imreconstruct(Ie, I);
Ioc=imclose(Io, se);
Iobrd=imdilate(Iobr, se);
Iobrcbr=imreconstruct(imcomplement(Iobrd), imcomplement(Iobr));
Iobrcbr=imcomplement(Iobrcbr);
fgm=imregionalmax(Iobrcbr);
I2=I;
I2(fgm)=255;
se2=strel(ones(5, 5));
fgm2=imclose(fgm, se2);
fgm3=imerode(fgm2, se2);
fgm4=bwareaopen(fgm3, 20);
I3=I;
I3(fgm4)=255;
bw=im2bw(Iobrcbr, graythresh(Iobrcbr));
D=bwdist(bw);
DL=watershed(D);
bgm=DL==0;
gradmag2=imimposemin(gradmag, bgm | fgm4);
L=watershed(gradmag2);
I4=I;
I4(imdilate(L==0, ones(3, 3))|bgm|fgm4)=255;
Lrgb=label2rgb(L, 'jet', 'w', 'shuffle');
grayimg = rgb2gray(Lrgb);
grayimg = imadjust(grayimg);
binar=im2bw(grayimg, 0.5)
binar=~binar
se = strel('disk',1);
bin = imopen(binar,se);
[B,L] = bwboundaries(bin);
stats = regionprops(L,'Centroid','EquivDiameter');
imshow(binar)
hold on
for k = 1:length(B)
boundary = B{k};
radius = stats(k).EquivDiameter/2;
xc = stats(k).Centroid(1);
yc = stats(k).Centroid(2);
theta = 0:0.01:2*pi;
Xfit = radius*cos(theta) + xc;
Yfit = radius*sin(theta) + yc;
plot(Xfit, Yfit, 'g');
text(boundary(1,2)-15,boundary(1,1)+15, num2str(radius,3),'Color','r',...
'FontSize',8);
set(handles.text2, 'string', num2str(radius));
vol=4*pi*radius*radius*radius/3;
set(handles.text7, 'string', num2str(vol));
I am trying to do so
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
f=str2num(get(handles.edit37, 'String'));
d=str2num(get(handles.edit38, 'String'));
for k=f:d
I=strcat('15min_',num2str(k),'jpg')
in=(d-f)
text(732,501,'…',...
'FontSize',7,'HorizontalAlignment','right')
hy=fspecial('sobel');
hx=hy';
Iy=imfilter(double(I), hy, 'replicate');
Ix=imfilter(double(I), hx, 'replicate');
gradmag=sqrt(Ix.^2+Iy.^2);
L=watershed(gradmag);
Lrgb=label2rgb(L);
se=strel('disk', 20);
Io=imopen(I, se);
Ie=imerode(I, se);
Iobr=imreconstruct(Ie, I);
Ioc=imclose(Io, se);
Iobrd=imdilate(Iobr, se);
Iobrcbr=imreconstruct(imcomplement(Iobrd), imcomplement(Iobr));
Iobrcbr=imcomplement(Iobrcbr);
fgm=imregionalmax(Iobrcbr);
I2=I;
I2(fgm)=255;
se2=strel(ones(5, 5));
fgm2=imclose(fgm, se2);
fgm3=imerode(fgm2, se2);
fgm4=bwareaopen(fgm3, 20);
I3=I;
I3(fgm4)=255;
bw=im2bw(Iobrcbr, graythresh(Iobrcbr));
D=bwdist(bw);
DL=watershed(D);
bgm=DL==0;
gradmag2=imimposemin(gradmag, bgm | fgm4);
L=watershed(gradmag2);
I4=I;
I4(imdilate(L==0, ones(3, 3))|bgm|fgm4)=255;
Lrgb=label2rgb(L, 'jet', 'w', 'shuffle');
grayimg = rgb2gray(Lrgb);
grayimg = imadjust(grayimg);
binar=im2bw(grayimg, 0.5)
binar=~binar
se = strel('disk',1);
bin = imopen(binar,se);
[B,L] = bwboundaries(bin);
stats = regionprops(L,'Centroid','EquivDiameter');
imshow(binar)
hold on
for k = 1:length(B)
boundary = B{k};
radius = stats(k).EquivDiameter/2;
xc = stats(k).Centroid(1);
yc = stats(k).Centroid(2);
theta = 0:0.01:2*pi;
Xfit = radius*cos(theta) + xc;
Yfit = radius*sin(theta) + yc;
if radius>250
plot(Xfit, Yfit, 'g');
text(boundary(1,2)-15,boundary(1,1)+15, num2str(radius,3),'Color','r',...
'FontSize',8);
set(handles.text2, 'string', num2str(radius));
vol=4*pi*radius*radius*radius/3;
set(handles.text7, 'string', num2str(vol));
j=str2num(get(handles.edit3, 'String'));
novradius=j*radius;
set(handles.text14, 'string', num2str(novradius));
novvol=4*pi*novradius*novradius*novradius/3;
set(handles.text12, 'string', num2str(novvol));
tmp_data=get(handles.uitable3,'Data');
if isnumeric(tmp_data)&& gt(size(tmp_data,1), 1)
for m=1:1:in
tmp_data(m, 2)=vol;
set(handles.uitable3, 'Data', tmp_data);
end
elseif iscell(tmp_data)&& gt(size(tmp_data, 1), d+(w+2))
for i=1:1:in;
tmp_data(m, 2)=num2cell(vol);
set(handles.uitable3, 'Data', tmp_data);
end;
end;
please, help me.... it is so important for me....

Risposte (1)

Andreas Goser
Andreas Goser il 28 Lug 2016
Modificato: Andreas Goser il 28 Lug 2016
I give my hint based on your text, I have not looked at the code. The idea to automatically process many images is based on creating a loop leveraging the DIR command. You could find all file names by file type, in a certain directory of other factors interesting for you by using the return values of the DIR command and run a loop.

1 Commento

But in this way, A have 3D matrix..But not all filters which I using in my program can work with 3D matrix

Accedi per commentare.

Categorie

Community Treasure Hunt

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

Start Hunting!

Translated by