MATLAB Answers

cropping a serie of images and save only the cropped part of it

조회 수: 2(최근 30일)
Murstoe
Murstoe 3 Apr 2020
댓글: darova 3 Apr 2020
Hi guys, I would be grateful if someone kindly could help me with this.
I have a serie of frames of the same image (.tif). I would like to load all the images (they become matrixes 2000*2000) from the folder and crop all of them with the same pattern (I dont know the coordinates of cropping so I would like to be allowed to choose a rectangular square in one of them and apply it to all). Then I would like to save them in a new folder in the same path.
clc;
clear;
close all;
% cd('C:\Users\...\OT pics')
% Sample
dirName = uigetdir('./', 'Select data folder');
cd(dirName);
for i=484:487
image_{i}=imread(sprintf('SI380820191011130728_%03d.tif',i));
[J,rect]=imcrop(image_{i})
[x,y]=size(image_{i});
X=1:x;
Y=1:y;
[xx,yy]=meshgrid(Y,X);
figure;imshow([J,rect])
colormap (jet)
colorbar
caxis([0 45000]);
axis on
fullFileName = fullfile('C:\Users\..\OT pics\new', [J,rect]);
saveas(mfig,fullFileName);
end
This is the script i have been using but it gives back this error. Anyone helping? Thanks a lot
Error using horzcat
Dimensions of arrays being concatenated are not consistent.
Error in Untitled2 (line 43)
figure;imshow([J,rect])

  댓글 수: 4

표시 이전 댓글 수: 1
Murstoe
Murstoe 3 Apr 2020
I would like to show the cropped images. So, that tool only returns me the coordinates, it does not actually croop it right?
Murstoe
Murstoe 3 Apr 2020
thanks a lot. However, now it let me choose a rectangle for every of the 4 pics. is it possible to automatically apply the cropping to all the 4 pictures?
....
image_{i}=imread(sprintf('SI380820191011130728_%03d.tif',i));
J=imcrop(image_{i})
[x,y]=size(image_{i});
X=1:x;
Y=1:y;
[xx,yy]=meshgrid(Y,X);
figure;imshow(J)
...

로그인 to comment.

채택된 답변

darova
darova 3 Apr 2020
Tri this (not tested)
dirName = uigetdir('./', 'Select data folder');
cd(dirName);
fname = sprintf('SI380820191011130728_%03d.tif',1)
image_{i} = imread(str);
[J,rect] = imcrop(image_{i})
for i = 2:487
fname = sprintf('SI380820191011130728_%03d.tif',i)
image_{i} = imread(str);
J = imcrop(image_{i},rect)
[x,y] = size(image_{i});
X=1:x;
Y=1:y;
[xx,yy]=meshgrid(Y,X);
figure
imshow(J)
colormap (jet)
colorbar
caxis([0 45000]);
axis on
fullFileName = fullfile('C:\Users\..\OT pics\new', [str num2str(i)]);
imwrite(J,fullFileName)
end

  댓글 수: 3

Murstoe
Murstoe 3 Apr 2020
thank you very much.
it still gives back an error in this line: "Unrecognized function or variable 'str' ". what do you mean by str?
image_{i} = imread(str)
darova
darova 3 Apr 2020
I believe i made a mistake.(never happened before)
darova
darova 3 Apr 2020
please change according to this

로그인 to comment.

추가 답변(0개)

이 질문에 답변하려면 로그인을(를) 수행하십시오.

제품


릴리스

R2019b

Translated by