Image patch extraction from given co-ordinate
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
MD RESHAD UL HOQUE
am 25 Jan. 2018
Bearbeitet: Rik
am 29 Jan. 2018
Hello everyone, I have an image [800 x 900 x 4]. I have to extract patches with a center point [(x1,y1),(x2,y2)... ]. How can I do that ?.
Thanks
2 Kommentare
Rik
am 25 Jan. 2018
What size should those patches be? And is your image a 3D gray scale image, or some other format? (YMCK perhaps?)
Akzeptierte Antwort
Rik
am 25 Jan. 2018
Bearbeitet: Rik
am 29 Jan. 2018
Your image is not 4D. It has 3 dimensions, unless what you posted in your question is not true.
patch{i}=IM(x(i)+[-8 8],y(i)+[-8 8],:);
This makes use of the quirk of Matlab that if you enter corner coordinates, it will return the entire square part.
For edge cases, the code below crops the part outside of the matrix (my comment below has a copy-and-past bug)
selected_patches = cell(length(x),1);
for i=1:length(x)
xtemp=x(i)+[-8 8];
xtemp(xtemp<1)=1;xtemp(xtemp>size(IM,1))=size(IM,1);
ytemp=y(i)+[-8 8];
ytemp(ytemp<1)=1;ytemp(ytemp>size(IM,2))=size(IM,2);
selected_patches{i}=IM(xtemp,ytemp,:);
end
Weitere Antworten (0)
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!