Image imcrop为1个变量

Image imcrop为1个变量,image,matlab,loops,image-processing,Image,Matlab,Loops,Image Processing,我使用同一个文件中的imcrop制作了一组新图片,使用此代码,我知道它很长,但由于距离并不总是相同,我发现除了此之外,没有其他方法: A001=imcrop(A,[65 159 95 332]); A002=imcrop(A,[182 161 95 332]); A003=imcrop(A,[297 164 95 332]); A004=imcrop(A,[402 165 90 332]); A005=imcrop(A,[495 168 90 332]); A006=imcrop(A,[606

我使用同一个文件中的
imcrop
制作了一组新图片,使用此代码,我知道它很长,但由于距离并不总是相同,我发现除了此之外,没有其他方法:

A001=imcrop(A,[65 159 95 332]);
A002=imcrop(A,[182 161 95 332]);
A003=imcrop(A,[297 164 95 332]);
A004=imcrop(A,[402 165 90 332]);
A005=imcrop(A,[495 168 90 332]);
A006=imcrop(A,[606 166 90 332]);
A007=imcrop(A,[705 171 90 332]);
A008=imcrop(A,[808 175 90 332]);
A009=imcrop(A,[922 175 90 332]);
A0010=imcrop(A,[1031 175 90 332]);
然后,我有一系列的任务要在每个新图像上执行,我如何以最简单的方式处理这些任务?当我从一个文件夹导入多个JPEG时,我可以让它生成文件的数据集,但当我尝试对A001:A0010执行相同操作时,我什么也得不到

这是我要执行的任务:

greenChannel = A(:, :, 2);

BW = edge(greenChannel,'Prewitt');
figure, imshow(BW)


 %Dialate Lines
se90 = strel('line', 3, 90);
se0 = strel('line', 3, 0);
BWsdil = imdilate(BW, [se90 se0]);;
figure, imshow(BWsdil), title('dilated gradient mask');


%Fill Lines
BWdfill = imfill(BWsdil, 'holes');
figure, imshow(BWdfill);
title('binary image with filled holes');


BWnobord = imclearborder(BWdfill, 4);
figure, imshow(BWnobord), title('cleared border image');

seD = strel('diamond',1);
BWfinal = imerode(BWnobord,seD);
BWfinal = imerode(BWfinal,seD);
figure, imshow(BWfinal), title('segmented image');

L = bwlabel(BWfinal);
s = regionprops(L,'centroid');

我需要帮助的是如何将A001:A0010放入顶部的A中并运行该命令序列,希望有人能帮助我实现这一点

这是多毛的,但这里是:

A = imread('peppers.png');
A = imresize(A, [1500 1500]); % to handle the indexing range.

A001=imcrop(A,[65 159 95 332]);
A002=imcrop(A,[182 161 95 332]);
A003=imcrop(A,[297 164 95 332]);
A004=imcrop(A,[402 165 90 332]);
A005=imcrop(A,[495 168 90 332]);
A006=imcrop(A,[606 166 90 332]);
A007=imcrop(A,[705 171 90 332]);
A008=imcrop(A,[808 175 90 332]);
A009=imcrop(A,[922 175 90 332]);
A0010=imcrop(A,[1031 175 90 332]);

w = who; % returns the names of all your current variables in a cell.

for i = 1:numel(w)
    % A00 is unique to all the variables you want to process.
    if ~isempty(strfind(w{i}, 'A00')) 
        % hard coding greenChannel and extracting the second plane.
        eval(['greenChannel = ',w{i},'(:,:,2)']); 
        % do the rest of the processing here, 
        % from BW = edge ... to regionprops. 
        % You may have to save the s structure as a cell array.
    end
end

这使用who命令提取所有当前变量,eval命令根据变量名计算作为文本传递的内容。请注意,使用eval是危险的,只有在没有更好的替代方案时才应使用eval。参见

你所说的“当我尝试对A001:A0010做同样的事情时,我什么也得不到”是什么意思?您试图用这些图像创建什么样的数据集?你有没有试过把图像放进细胞阵列?非常感谢你的帮助!节省了我很多时间!只有一个问题,我不知道如何将s结构保存为单元格数组。我尝试了struct2cell命令,但没有成功。问题是s的大小从3x1 struct到7x1 struct不等,我似乎无法确定outso struct2cell将尝试从您的结构创建一个单元格。我想你不想那样。您可以使用{}构造函数将整个结构保存到一个单元格元素中。例如,s.a=1;s、 b=2;s、 c=3;s2.a=1;s2.b=2;迈塞尔{1}=s;迈塞尔{2}=s2;等等希望有帮助!