How can I crop the image at a particular location each time?
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Suyog Pathare
le 8 Fév 2022
Réponse apportée : yanqi liu
le 9 Fév 2022
I have multiple rbg images. I want to analyze them for pixel calculation. But I only want a part of it. How can I crop all the images at the exact same location?
0 commentaires
Réponse acceptée
yanqi liu
le 9 Fév 2022
yes,sir,just use imcrop can get target area image,if multi image do not have same size,may be use width and height rate,such as
clc; clear all; close all;
files = {'cameraman.tif', 'football.jpg', 'rice.png'};
rect = [0.2 0.3 0.4 0.3];
for i = 1 : length(files)
% get image
imi = imread(files{i});
sz = size(imi);
% get rect
recti = rect .* [sz(2) sz(1) sz(2) sz(1)];
% crop image
imi2 = imcrop(imi, round(recti));
figure;
subplot(1,2,1); imshow(imi, []);
hold on; rectangle('position', recti, 'EdgeColor', 'r', 'LineWidth', 2)
subplot(1,2,2); imshow(imi2, []);
end
0 commentaires
Plus de réponses (2)
HighPhi
le 8 Fév 2022
Your rgb images are an X x Y x 3 array,
where, visually, X is actually image height and Y is actually image width
If you imaging that the top left corner of your image is 0,0
you can get another smaller cropped area via:
rgb2 = rgb1(X1:X2, Y1:Y2, :);

0 commentaires
David Hill
le 8 Fév 2022
Modifié(e) : David Hill
le 8 Fév 2022
Your rbg image is just a matrix. Just index into the matrix at the location you want.
x=uint8(randi(255,1000,1000,3));
imshow(x(10:10,50:80,:));
0 commentaires
Voir également
Catégories
En savoir plus sur Get Started with Image Processing Toolbox dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


