How to count number of legos? [closed] - matlab

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I have an image of Lego bricks which I have segmented in order to get only the blue and red colored bricks.
I also have two templates of bricks that I want to find.
I want to count the number of each of the template bricks in the image. I thought of counting the number of circles on top of the bricks, but some of the bricks are flipped. How could I do this?

Counting the number of circles on top of the bricks could be a very difficult task. A better solution is to look after better properties such like the relation between the hight and the width of the brick.
A possible start for segmentation is as follows:
E = regionprops(L,'all'); % E contains all properties
area = cat(1, E.Area) % saves the area in a variable
cp = cat(1,E.Centroid) % saves the center of the object
figure,imshow(label2rgb(L));
hold on; plot(cp(:,1), cp(:,2), 'b*'); % displays the center of the objects
It will show you your segmentation and will display some information about the properties of the obejects. From there on you will be able to look for what properties you are watching for and can select them in if statements. Depending on your image and your selected properties this could take up to 10 properties but most likely will be around 5.
For further information look here: MATLAB segmentation overview

Related

How to stack a series of images in MATLAB [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
clc;clear all;
Imatrix = []
for i=1:3
images{i} = imread(sprintf('frame-1065.png',i));
Imatrix = cat(3, Imatrix, images{i});
D = Imatrix;
end;
imshow(D)
This is the code I'm trying to run but the problem is I have 2000 pictures and I am only able to get one to be displayed.
I think what you really want is to store the images as image stacks.
This will allow you to view the image stack in e.g. ImageJ and scroll through it etc.
I would store them as one single tiff file and do something like this (please note that all your images must be of the same size):
numOfImages = 2000;
output_filename = 'imgstack.tif';
for k=1:numOfImages
loaded_image = imread(sprintf('frame-%d.png',k));
imwrite(loaded_image, output_filename, 'WriteMode',append','Compression','none');
end
The issue is visualization. You can view either an MxNxP stack or a cell array where each cell represents an image using the montage function.
https://www.mathworks.com/help/images/ref/montage.html
figure, montage(images)
In your code above.
If you want to visualize your data as a volume, which you've indicated in the most recent comment, then volshow or volumeViewer in IPT will do that.
volumeViewer(Imatrix)
figure, volshow(Imatrix)
Where Imatrix is an MxNxP array that you want to perform volume visualization on.

Determination of area of circular object in image [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I want to determine area of circular object in image below using MATLAB. Can someone explain codes for doing that? I got thresholded image but I did not proceed more.
If the binary image is img, and it contains only values 0 (background) and 1 (object), or it is a logical array containing true and false, and all the object pixels are considered part of the object, then sum(img(:)) is the area of the object in pixels.
If the segmented image contains multiple objects, or noise, it will have to be filtered first to leave only the pixels that belong to the one object.
To convert the area in pixels to an area in physical units you need to know the size of a pixel. This is often obtained by adding a ruler to the image.

How to change Matlab's scaling process when not Native? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I would like to change the downsampling method or the process by which Matlab changes picture when resolution is not native.
I am especially interested in the scaling methods which are suitable for scientific computing in grayscale.
Default Matlab 2016a's warning whatever the scaling is
Warning: Image is too big to fit on screen; displaying at 50%.
Either the scaling is 10^-6 or 1/2, my Matlab 2016a always says that it is 50%, which is irritating.
How can you change Matlab's downsampling method or corresponding scaling process?
When displaying an image you should use imshow.
In imshow you can set the zoom level.
Look at the ImshowInitialMagnification property of imshow.
For instant:
mInputImage = imread('cameraman.tif');
imshow(mInputImage, 'ImshowInitialMagnification', 100);

Color a Point Cloud- Matlab [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I have a ply image. I want to color it according to my requirement.
1. (.ply) image from kinect
2. Change the rgb value of all point in cloud
e.g
.ply image where all points in the cloud are to be in yellow or blue color.
I have been able to display it using Matlab command "scatter3" but also want to save the colored point cloud as a new point cloud by "pcwrite" function of Matlab.
To answer properly to this question I should know which version of Matlab are you using. If you are using Matlab 2015a you should have these three function
pcread to read a 3D point cloud (.ply file);
pcshow to show a 3D point cloud;
pcwrite to write a .ply file.
Let's say your image is called "airplane.ply".
To properly use that you first read the image using:
ptCloud = pcread('airplane.ply')
then you will notice that ptCloud has different field. One of that regard the color, and is the one you have to change. To do so you have to specify a colour for each point in the cloud. So:
pointscolor=uint8(zeros(ptCloud.Count,3));
pointscolor(:,1)=255;
pointscolor(:,2)=255;
pointscolor(:,3)=51;
since [255 255 51] is the yellow color.
Then assign this matrix to the ptCloud.Color.
ptCloud.Color=pointscolor;
See the result:
pcshow(ptCloud)
and save the file:
pcwrite(ptCloud,'ptCloud.ply')
where 'ptCloud.ply' is the name you want to assign to the file.

"I = [MxNx4]" meaning? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I am doing an image processing project. In my project there is an GUI file that reads an image and processing it for segmentation. while reading an image file, initially it is checking the size of that image... However, I don't understand what the function I=[m x n x 4] really means. Could someone explain this to me?
Your image I is of size m pixels high by n pixels wide and has 4 channels: Red, Green, Blue and an alpha channel.
Matlab stores I as a 3D array, you can access the x-y-th pixel by I(y,x,:) returning the four-vector representing the RGBA value of the x-y-th pixel.