how to detect center of an object in an image and then crop the original image? using original image and green outline region
9 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hello.
I need to detect an object (suspicious area in an image). Then I need to find its centroid and then crop it the image into 256x256 pixels using image centroid as the centre of bounding box.
img = imread('1_245_original.jpg');
% colorspace
jmg = rgb2gray(img);
jm = mat2gray(jmg(:,:,1));
jm = imcomplement(jm);
% thresh
bw = imbinarize(jm, graythresh(jm));
% filter noise
bw = imopen(bw, strel('disk', 5));
bw = imfill(bw, 'holes');
% label every target
[L,num] = bwlabel(bw);
stats = regionprops(L);
figure; imshow(img, []);
for i = 1 : num
% get rect
recti = stats(i).BoundingBox;
% get cen
ceni = stats(i).Centroid;
% crop image
imi = imcrop(img, round(recti));
ims{i} = imi;
% rect and cen
hold on; rectangle('Position', recti, 'EdgeColor', 'c', 'LineWidth', 2);
plot(ceni(1), ceni(2), 'yp', 'MarkerFaceColor', 'y', 'MarkerSize', 20);
end
I have tried out this code, but the cropping area was not in 256x256 pixels. and I want it to save at folder after detect the bounding box. Where can I put that code? Thanks.
1 commentaire
Image Analyst
le 20 Mai 2024
You've asked this before. Finding dark regions is not a problem, nor is cropping them and resizing them. The problem is identifying which of the many dark regions in the image is the specific one you want, and you haven't specified what it is about that dark blob that distinguishes it from all the other dark blobs. Yes, I know you've said that it is diseased tissue but how does it LOOK different than all the others?
Réponses (0)
Voir également
Catégories
En savoir plus sur 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!