How do I save a variable in a for loop by using the same name but changing the number.
조회 수: 3 (최근 30일)
이전 댓글 표시
Hello,
As you can see from my code below, I am getting an image of 5 cells and placing a bounding box around each one. After producing the bounding box, I simply wanted to crop each separate cell into its own image separate image labeled 'Crop_1', 'Crop_2', etc. In order to do that I need to save the variable within each loop in order for it to not be overwritten by the next loop. Currently, my code will only crop the image of the last loop run.
So in other words, how do I write code within a loop to save the output of the loop as a variable and just simply making the variable name Crop_(i) with i representing the specific number cell.
Thank you in advanced
for i = 1:length(stats)
Cell_i = stats(i).BoundingBox;
rectangle('Position', [Cell_i(1),Cell_i(2),Cell_i(3),...
Cell_i(4)],'EdgeColor',cstring(mod(i,5)+1),'LineWidth',2);
disp(['Cell ', num2str(i), ' : ',num2str(stats(i).Area)]);
end
crop_img = imcrop(final_img,Cell_i);
imshow(crop_img)
imwrite(crop_img,'cell1.tif')
댓글 수: 0
답변 (2개)
Image Analyst
2014년 4월 18일
See my tutorial where I extract/crop subimages that have blobs of interest (coins) in them: http://www.mathworks.com/matlabcentral/fileexchange/?term=authorid%3A31862
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!