Effacer les filtres
Effacer les filtres

How to divide an image into 8 equal sectors?

3 vues (au cours des 30 derniers jours)
anastasia
anastasia le 20 Avr 2017
Commenté : Image Analyst le 24 Avr 2017
I have an image. I need to divide the image into 8 equal sectors as shown below.
I have used the following code:
clear all;
close all;
im=imread('apple.jpg');
r=100;
out1 = ones(max(size(im,1),r*2)+2,max(size(im,2),r*2)+2,3).*255;
xoffset = floor((size(out1,2)-size(im,2))/2);
yoffset = floor((size(out1,1)-size(im,1))/2);
out1(yoffset:yoffset+size(im,1)-1,xoffset:xoffset+size(im,2)-1,:) = im(:,:,:);
im = out1;
cy = floor(size(im,1)/2);
cx = floor(size(im,2)/2);
figure;
imshow(uint8(im));
hold on
pos = [cx-r+1 cy-r+1 r*2 r*2];
rectangle('Position',pos,'Curvature',[1 1]);
x1 = [-r, 0, -r*cosd(45), -r*cosd(45); r, 0, r*cosd(45), r*cosd(45)]+cx+1;
y1 = [0, -r, -r*sind(45), r*sind(45); 0, r, r*sind(45), -r*sind(45)]+cy+1;
plot(x1,y1);
hold off
figure;
for i = 0:45:315
t = linspace(-i,-i-45,128);
x = [cx, cx+r*cosd(t), cx];
y = [cy, cy+r*sind(t), cy];
bw = poly2mask( x, y, size(im,1),size(im,2));
bw = repmat(bw,1,1,3);
out = ones(size(im,1),size(im,2),size(im,3)).*155;
out(bw) = im(bw);
subplot(2,4,(i/45)+1); imshow(uint8(out));
end;
I need to do this for a dataset of over 100 images with different sizes. My problem is that, I have to manually assign the value for r for every image. How can I automatically assign the value for r? Please help. I also need to minimize the background (white parts) in the sectors as much as possible. How do I go about this? Please help. Thank you.

Réponse acceptée

Image Analyst
Image Analyst le 20 Avr 2017
  3 commentaires
anastasia
anastasia le 24 Avr 2017
I am getting the background white pixels into my sectors. How do I eliminate those?
Is it possible to split ONLY the apple image into equal parts using the centroid and the major and minor axis?
I do not want the background pixels in my split parts, just the ROI pixels.
Please guide.
Image Analyst
Image Analyst le 24 Avr 2017
Find the apple mask by converting to hsv colorspace with rgb2hsv() then thresholding the S channel. The apple will have S values more than about 0.2. Now you have a mask and you can use it to blacken outside the apple, crop the image, or both.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Image Processing Toolbox dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by