how to detect center of an object in an image and then crop the original image? using original image and green outline region
10 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Dayangku Nur Faizah Pengiran Mohamad
el 20 de Mayo de 2024
Comentada: Image Analyst
el 20 de Mayo de 2024
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 comentario
Image Analyst
el 20 de Mayo de 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?
Respuestas (0)
Ver también
Categorías
Más información sobre Image Processing Toolbox en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!