PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, July 27, 2022

[FIXED] How to crop Top, Left, Bottom, and Right boundaries in an image?

 July 27, 2022     crop, edge-detection, image, image-processing, matlab     No comments   

Issue

I'm trying to crop the top, left, bottom, and right boundaries of the image below.

Image to Crop

So, basically, I'm looking to create something that would take the image above as the input and output these images:

North Crop

West Crop

South Crop

East Crop

The straight lines and their dimensions can be detected using houghlines in MATLAB, but how can I find the positions of the convex and concave pieces in the image? I tried using regionprops and the extrema property, but it would not detect the concave curves (only gave points for the extrema of the convex curves.) I need to find out the lowest/highest points in the concave/convex curves but I'm not sure how to go about that. I have the step after that figured out though; I can easily use imcrop to crop out the respective boundaries once I know them.


Solution

Code

%%// Tolerance in percentage for the outliers/noise in the image because 
%%// of which the edges are not perfectly vertical or horizontal and 
%%// the ovalish blobs are not "round" enough
f=2;

%%// Read in your image
img = im2bw(imread('patt1.png'));

%%// Main processing
sum1 = sum(img,1);
box_startx = find(sum1>0.33*size(img,1),1);
box_stopx = size(img,2) - find(fliplr(sum1)>0.33*size(img,1),1) + 1;

sum2 = sum(img,2)'; %'
box_starty = find(sum2>0.33*size(img,2),1);
box_stopy = size(img,1) - find(fliplr(sum2)>0.33*size(img,2),1) + 1;

blob_leftx = find(sum1>(1-0.01*f)*max(sum1),1);
blob_rightx = size(img,2) - find(fliplr(sum1)>(1-0.01*f)*max(sum1),1) + 1;

blob_topy = find(sum2>(1-0.01*f)*max(sum2),1);
blob_bottomy = size(img,1) - find(fliplr(sum2)>(1-0.01*f)*max(sum2),1) + 1;

top1 = img(1:blob_topy,box_startx+1:box_stopx);
left1 = img(box_starty:box_stopy-1,1:blob_leftx);
bottom1 = img(blob_bottomy:end,box_startx:box_stopx);
right1 = img(box_starty:box_stopy,blob_rightx:end);

%// Debug
figure,
subplot(2,2,1);imshow(top1)
subplot(2,2,2);imshow(bottom1)
subplot(2,2,3);imshow(left1)
subplot(2,2,4);imshow(right1)

Output

enter image description here



Answered By - Divakar
Answer Checked By - Mildred Charles (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing