フィルターのクリア

Crop images using coordinates and save them

20 ビュー (過去 30 日間)
Anounymous85
Anounymous85 2019 年 1 月 29 日
コメント済み: Aytaç Tok 2021 年 3 月 12 日
I am cropping an image using some x, y coordinates. After the cropping i can save the cropped image. Is there a way i can save both cropped image as well as the rest?
(What i meant by rest is the remaining part of the image, what i got after removing the cropped image).
Please help me.
Thanks!

回答 (3 件)

Image Analyst
Image Analyst 2019 年 1 月 29 日
Use imwrite()
imwrite(croppedImage, croppedFileName);
The original image is most likely already saved, if you read it in using imread().
  3 件のコメント
Image Analyst
Image Analyst 2019 年 1 月 29 日
OK, and my answer will let you save that cropped image you got. I believe I answered your problem - you need to use imwrite(). First on the image you showed, then on the "other half of the image". Do you still have a problem? If so, what is it?
Image Analyst
Image Analyst 2019 年 2 月 16 日
Since it appears that the problem you're trying to communicate is that your image is not being cropped correctly, I believe you're making the common beginner mistake of assuming that arrays are indexed (x,y) instead of (y, x). The first index is y, which is row, and the second index is x, which is column. So try this:
[rows, columns] = find(binaryImage); % or [y, x] = find(binaryImage);
row1 = min(rows);
row2 = max(rows);
col1 = min(columns);
col2 = max(columns);
imwrite(binaryImage(row1:row2, col1:col2), fileName);

サインインしてコメントする。


Mark Sherstan
Mark Sherstan 2019 年 1 月 29 日
You will need to fill in the "hole" with white or black pixels. Give something like this a try:
I = imread('test.png');
J = imcrop(I,[200 200 400 600]);
I(200:600,200:800,:) = 0;
figure(1)
subplot(1,2,1); imshow(J)
subplot(1,2,2); imshow(I)
Or if you are splitting the image in half try cropping twice like so:
I = imread('test.png');
idx = size(I);
J = imcrop(I,[0 0 idx(2)/2 idx(1)]);
K = imcrop(I,[idx(2)/2 0 idx(2) idx(1)]);
figure(1)
subplot(1,2,1); imshow(J)
subplot(1,2,2); imshow(K)
  4 件のコメント
Anounymous85
Anounymous85 2019 年 2 月 16 日
I guess the first solution you have provided here can help me with what i want. Thank you!
But only problem I have is my x, y, width and height values are getting changed for different pictures. It is not easy to change those values time to time. I just want to get those values automatically, matching tto different images.
Mark Sherstan
Mark Sherstan 2019 年 2 月 16 日
How does your area change from picture to picture? Can you find the size of the image and then just take a percentage of that? E.g:
I = imread('test.png');
[height, width, ~] = size(I);
J = imcrop(I,[0 0 width/2 height]);
imshow(J)

サインインしてコメントする。


Aytaç Tok
Aytaç Tok 2021 年 3 月 11 日
How do I crop a picture using border coordinates.I have 1695x2 size limit values. How do I crop the object inside these values ​​from the original picture?
  2 件のコメント
Image Analyst
Image Analyst 2021 年 3 月 11 日
You can use imcrop() or indexing. If you need additional help, start a new question and attach your image, and a mat file with your "limit values" or "boundary coordinates" in a .zip file with the paper clip icon.
Aytaç Tok
Aytaç Tok 2021 年 3 月 12 日
I shared the image.I just want to crop the banana picture here, so the rgb banana picture in the nerve pixel values
clc;close all;clear all
e=imread('muzpp.jpeg');
l=imbinarize(rgb2gray(e));
grayImage=rgb2gray(e);
gri=grayImage;
[r c]=size(l);
sb=imbinarize(gri);
sb=bwareaopen(sb,10);
se=strel('disk',5);
sb=imclose(sb,se);
sb=imfill(sb,'holes');
se2=strel('disk',30);
sb2=imerode(sb,se2);
[etiket nesnesayisi]=bwlabel(sb2,4);
[sinirkordinatlari etiketler]=bwboundaries(sb2);
[etiketler nesnesayisi]=bwlabel(sb2,4);
for k=1:length(sinirkordinatlari)
sinir=sinirkordinatlari{k};
end
imshow(e)

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeImage Processing and Computer Vision についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by