How to Crop A bunch of image with same box but different position

1 回表示 (過去 30 日間)
Martino Corno
Martino Corno 2020 年 3 月 23 日
コメント済み: Martino Corno 2020 年 3 月 28 日
Hi ,
I'm trying to cropping polygons out of a bunch of images where the polygon's dimention and shape is always the same but I can choose the position changing the center or a vertex. I already made a code that allow me to do this with a rectangle but i want to change the shape. Anyone can help me please?
figure
imshow(read(DatabaseTest , i))
hold on
[x0,y0] = ginput(1);
J = imadjust(rgb2gray(read(DatabaseTest , i)));
ImageTest = imcrop(J,[x0 - width / 2,y0 - height / 2,width,height]);
this is a part of a code able to extract HOG Features so I change rgb2gray to reduce noise effects (if you want you can also suggest me any tips).

採用された回答

Ani Singh
Ani Singh 2020 年 3 月 26 日
You can do this by using roipoly function.
I am attaching sample script for it :
% read the image
input = imread (I)
%Co-ordinates of selected area(change thee according to your requirements)
r=[40 204 267 102];
c=[136 125 210 219];
BW=roipoly(input,r,c);
%replacing white area with the desired image
out=zeros(size(BW,1),size(BW,2));
out = gray .* uint8(BW); %store those pixels in output which are selected, can be done by 2 for loops also
imshow(out)
  1 件のコメント
Martino Corno
Martino Corno 2020 年 3 月 28 日
Thanks very much,
I understood what this code want to performe but 'BW' and 'gray' are not the same class of integer . I copied and pasted your code, but the matrix moltiplication doesn't seems to work for my case, I also change with function uint8 the class of matrix 'gray' but it doesn't work as well . Do you have any suggestion?

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

その他の回答 (0 件)

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by