필터 지우기
필터 지우기

crop a region of interest on images and create new files only with this region

조회 수: 5 (최근 30일)
Dear all,
I am writing to you because I am new to Matlab and I would be very grateful if you could help me. I have images from 20 sections from t=0 to t=70 (which would make for 1420 images, beginning with z0000_t0000, z0001_t0000... leading up to z00019_t0069, size of the field 200x200, pixels 521x512), that I normally put into Z-stack and analyse over time with ImageJ. However, I would like to have a Matlab program that would extract only one region of the image (that I would choose, either draw manually or by establishing coordinates, but I have no idea how establish the coordinates?) and create 1420 images (either new 1420 images, or transform the original image into images with the ROI) only with that region. Is it possible, and could you please help me do it? Thank you very much.

채택된 답변

MHN
MHN 2016년 3월 9일
편집: MHN 2016년 3월 9일
Im = imread('ngc6543a.jpg'); %load your image
image(Im)
x_start = 50; % start x
x_end = 500; % end x
y_start = 50; % start y
y_end = 500; % end x
Im1 = Im([x_start:x_end],[y_start:y_end],:);
figure
image(Im1)
imwrite(Im1,'newimage.jpg') % save the croped image
To find your coordinates, you can see the original picture (Im), use the "data cursor" and you can find your min\max x and min\max y.

추가 답변 (2개)

Anastasia
Anastasia 2016년 3월 9일
Thank you very much for your response! Is it possible to create a while...to program (or something like that), so that I could put all the pictures from one folder (from z0000_t0000 to z0019_t0069, and not one by one? Thank you again!!
  댓글 수: 3
Image Analyst
Image Analyst 2016년 3월 12일
You have to process them one by one, but you can put the processing into a loop so that it's essentially a batch process. Code for this is in the FAQ: http://matlab.wikia.com/wiki/FAQ#How_can_I_process_a_sequence_of_files.3F
MHN
MHN 2016년 3월 12일
If I want to integrate the answers (Just save the following code in the same path as your image's files):
for i = 0 : 19;
for j = 0 : 69;
filename = ['z00' sprintf('%02d',i) '_t00' sprintf('%02d',j) '.jpg'];
Im = imread(filename);
x_start = 50; % start x
x_end = 500; % end x
y_start = 50; % start y
y_end = 500; % end x
Im_new = Im([x_start:x_end],[y_start:y_end],:);
imwrite(Im_new, filename) % replace the croped image
end
end

댓글을 달려면 로그인하십시오.


Anastasia
Anastasia 2016년 4월 3일
Thank you so much, it works perfectly!!! Thank you!
  댓글 수: 1
Image Analyst
Image Analyst 2016년 4월 3일
Be very careful when using MHN's code because he made the common mistake of swapping x and y.
Images are arrays, and are indexed like arrays as (row, column), NOT (x,y) as he had. You will need to swap all of his x,y with y,x to get his code to work properly.

댓글을 달려면 로그인하십시오.

태그

Community Treasure Hunt

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

Start Hunting!

Translated by