How can i loop this code?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
george korris
el 21 de Abr. de 2021
Comentada: george korris
el 28 de Abr. de 2021
Hey guys so i have the next code which reads an image then crops it and then for the same crop diensions crops 15 mor images and the for each image does some fft staff the same for every image and in the end finds the slopes of the polyfits and plots them in one diagramme.How can i make this do all of them faster?
clc;
clear all;
img = imread('a=0.3.1.jpg');
figure;
imshow(img);
h_rect = imrect();
% Rectangle position is given as [xmin, ymin, width, height]
pos_rect = h_rect.getPosition();
% Round off so the coordinates can be used as indices
pos_rect = round(pos_rect);
% Select part of the image
img_cropped = img(pos_rect(2) + (0:pos_rect(4)), pos_rect(1) + (0:pos_rect(3)));
img = img_cropped
img_rot=imrotate(img,32.06);
figure, imshow(img_rot)
%figure,contourf(prof_img_rot11);
fft_prof11 = mean(abs(fft(prof_img_rot11)'));
img = imread('a=0.3.2.jpg');
img = imcrop(img,pos_rect);
imshow(img)
img_rot=imrotate(img,32.06);
figure, imshow(img_rot)
%figure,contourf(prof_img_rot12);
fft_prof12 = mean(abs(fft(prof_img_rot12)'));
img = imread('a=0.3.3.jpg');
img = imcrop(img,pos_rect);
imshow(img)
img_rot=imrotate(img,32.06);
figure, imshow(img_rot)
%contourf(prof_img_rot13);
fft_prof13 = mean(abs(fft(prof_img_rot13)'));
img = imread('a=0.3.4.jpg');
img = imcrop(img,pos_rect);
imshow(img)
img_rot=imrotate(img,32.06);
figure, imshow(img_rot)
%figure,contourf(prof_img_rot14);
fft_prof14 = mean(abs(fft(prof_img_rot14)'));
img = imread('a=0.5.1.jpg');
img = imcrop(img,pos_rect);
imshow(img)
img_rot=imrotate(img,32.06);
figure, imshow(img_rot)
%figure,contourf(prof_img_rot21);
fft_prof21 = mean(abs(fft(prof_img_rot21)'));
img = imread('a=0.5.2.jpg');
img = imcrop(img,pos_rect);
imshow(img)
img_rot=imrotate(img,32.06);
figure, imshow(img_rot)
%figure,contourf(prof_img_rot22);
fft_prof22 = mean(abs(fft(prof_img_rot22)'));
img = imread('a=0.5.3.jpg');
img = imcrop(img,pos_rect);
imshow(img)
img_rot=imrotate(img,32.06);
figure, imshow(img_rot)
%contourf(prof_img_rot23);
fft_prof23 = mean(abs(fft(prof_img_rot23)'));
x = 1:127;
x1 = log(x);
y11 = log(fft_prof11(2:128))
y12 = log(fft_prof12(2:128))
y13 = log(fft_prof13(2:128))
y14 = log(fft_prof14(2:128))
y21 = log(fft_prof21(2:128))
y22 = log(fft_prof22(2:128))
y23 = log(fft_prof23(2:128))
y24 = log(fft_prof24(2:128))
y31 = log(fft_prof31(2:128))
y32 = log(fft_prof32(2:128))
y33 = log(fft_prof33(2:128))
y34 = log(fft_prof34(2:128))
close all;
0 comentarios
Respuesta aceptada
Jan
el 26 de Abr. de 2021
Editada: Jan
el 26 de Abr. de 2021
Faster: Omit the clear all. It removes all loaded functions from the memory. Reloading and parsing them from the slow disk wastes time without any benefit.
For a loop over files, see: https://www.mathworks.com/matlabcentral/answers/57446-faq-how-can-i-process-a-sequence-of-files
3 comentarios
Más respuestas (0)
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!