[Solved] How can I detect the dimensions of an object under an angle in this picture in MATLAB? [closed]

Introduction

This question is about how to detect the dimensions of an object under an angle in a picture using MATLAB. MATLAB is a powerful tool for image processing and can be used to detect the dimensions of an object in a picture. In this article, we will discuss how to use MATLAB to detect the dimensions of an object under an angle in a picture. We will discuss the various techniques that can be used to detect the dimensions of an object in a picture and how to use MATLAB to implement them. We will also discuss the advantages and disadvantages of each technique and how to choose the best one for your application.

Solution

The best way to detect the dimensions of an object under an angle in a picture in MATLAB is to use the Image Processing Toolbox. This toolbox provides a variety of functions for image analysis, including functions for measuring the size of objects in an image.

For example, the regionprops function can be used to measure the size of objects in an image. This function takes an image as input and returns a structure containing information about the objects in the image, including their size.

In addition, the imfindcircles function can be used to detect circles in an image. This function takes an image as input and returns the center and radius of any circles detected in the image. This can be used to measure the size of objects in an image that are circular in shape.

Finally, the imfindline function can be used to detect lines in an image. This function takes an image as input and returns the endpoints of any lines detected in the image. This can be used to measure the size of objects in an image that are linear in shape.


Consider this as a beginner’s tutorial to Matlab image processing. Read the documentation of the commands used and try and understand what they are doing and why.

1. Read the image

Use imread to read the image into a 3D matrix. For convenience, we convert it to double in the range [0..1] using im2double:

>> img = im2double( imread( 'path/to/battety.jpg' ) );

You can check out the size of your img using size command:

>> size( img )
ans =
    1024         768           3

You can see from the result that your image has 1024 rows, 768 columns and 3 channels (Red, Green and Blue).

2. Convert to black and white (a.k.a thresholding)

As you can see the battery is significantly brighter than the background and is colorless. We can select pixels that have large gap between the brightest channel value to darkest channel values as “battery” pixels:

>> bw = (max(img,[],3)-min(img,[],3)) > 0.2;

See max and min for more details.
There are other methods to threshold an image, see graythresh for more details.

Using imshow we can see what we got:

>> imshow(bw,[],'border','tight');

enter image description here

Normally one uses morphological operations to improve thresholding results.
You can use imclose:

>> bw = imclose( bw, ones(25) );

Resulting with:
enter image description here

3. find angle of rotation

A very useful command for processing and working with bw images is regionprops. It allows you to get all sorts of nice properties. You are going to use it to compute the 'Orientation' of the “white”/battery region of your image

>> st = regionprops( bw, 'Orientation' )
st = 
Orientation: 52.8694

As you can see the battery is rotated by 52.8 degrees.
Using imrotate to “straighten” the battery

>> rbw = imrotate( bw, -st.Orientation );

Once the battery is axis-aligned, you can “project” the white pixels onto the horizontal and vertical axes using any:

>> pc = any( rbw, 2 ); %// project all rows into a single column 
>> pr = any( rbw, 1 ); %// project all columns into a single row

Now you need to find the first and last pixels set to 1 in the projections. Use find for that:

>> fx = find( pr, 1, 'first');  %// first x coordinate
>> tx = find( pr, 1, 'last');   %// last x coordinat
>> fy = find( pc, 1, 'first');  %// first y coordinate
>> ty = find( pc, 1, 'last');   %// last y coordinate  

Once you have x,y coordinates of corners, you can plot them on the rotated image:

>> imshow(rbw,[],'border','tight');
>> hold on; 
>> plot( [fx tx tx fx fx], [fy fy ty ty fy], ':r', 'LineWidth',3);

Yields:
enter image description here

And the coordinates are:

>> [fx fy tx ty]
ans =
406   608   866   733

As you can see your battery is (866-406) pixels long and (733-608) pixels wide.

0

solved How can I detect the dimensions of an object under an angle in this picture in MATLAB? [closed]



MATLAB provides a number of tools for detecting the dimensions of an object under an angle in a picture. The most straightforward approach is to use the Image Processing Toolbox. This toolbox provides a number of functions for detecting objects in an image, including the regionprops function.

The regionprops function can be used to detect the dimensions of an object in an image. This function takes an image as an input and returns a structure containing information about the objects in the image. The structure contains information about the size, orientation, and other properties of the objects.

To detect the dimensions of an object under an angle in an image, the regionprops function can be used in conjunction with the imrotate function. The imrotate function takes an image as an input and rotates it by a specified angle. The regionprops function can then be used to detect the dimensions of the object in the rotated image.

In summary, MATLAB provides a number of tools for detecting the dimensions of an object under an angle in a picture. The most straightforward approach is to use the Image Processing Toolbox and the regionprops and imrotate functions.