how to select a specified region in an image based on location and calculate its area

I want to calculate the area of the material included in each pucket?

2 Commenti

What is the material, and what is a pucket?
The lighting is very bad. Try to improve it and your task will be a LOT easier.
See my File Exchange for several image segmentation demos http://www.mathworks.com/matlabcentral/fileexchange/?term=authorid%3A31862
Thanks for your interest in answering me.
The material is sand, and the bucket is the lifter used to carry the material and then cascading it (make it fall) vertically.
I want to write a simple code to calculate the vertical area of the material carried by each bucket. and I want to define each bucket location by its angular position. i.e. the first bucket at the left down side where the angle said to be zero (horizontal) and then the next one at angle 30 from the horizontal.....
I tried to use imageJ software first to make filtration but it failed because I found the logic selection in bw all white?

Accedi per commentare.

 Risposta accettata

use p=roipoly() to draw a polygon around the area you want to measure it's area.
then the area would be sum(p(:))*pixelsize^2 if you want to automate this, then you need to first write a code that detects those region that you want.

2 Commenti

Thanks for your interest in answering me.
The material is sand, and the bucket is the lifter used to carry the material and then cascading it (make it fall) vertically.
I want to write a simple code to calculate the vertical area of the material carried by each bucket. and I want to define each bucket location by its angular position. i.e. the first bucket at the left down side where the angle said to be zero (horizontal) and then the next one at angle 30 from the horizontal.....
I tried to use imageJ software first to make filtration but it failed because I found the logic selection in bw all white?
But, I want matlab to draw such polygons autmatically by detecting the sand color which is yellow......and do not how?

Accedi per commentare.

Più risposte (1)

I don't know what/where the bucket is, what/where the sand is, and where the shadows are. The lighting is horrible and could definitely be improved. Plus who's idea was it to have a sand-colored background when you want to find sand pouring in front of it?!?! The disc thing should be black or at least some contrasting color. I'd fix all that first since it's far easier to design an image analysis algorithm if you have a good image to start with.

11 Commenti

Ok, the Pocket (sorry for wrong spelling) you can also call it as (lifter) it is attached to the main big cylinder. its function is to lift the material (sand) while the main cylinder rotates, and then make it falls down. My target is to know how mauch material carried by the lifter and that is can be by knowing the frontal area of the material, which is vary with the lifter position while the main cylinder rotates. At the beginning of doing such experimental work, I planned to use manual method by using ImageJ software. And I already finished, That is why the test rig was planned with these colors and lighting to be easy for the manual use. However this method is accurate but it consumes large time when you deal with hundreds of photos. So, now I under stood I can use Automated way "matlab image processing" but I cant change the background color to black and also the lighting...So please tell me how to use matlab for such conditions....Thanks a lot
also, how I set a scale for the image in matlab?
I did small effort, may be you can see this simple code...
clc; clear all;close all;
a = imread('1rpm.jpg');
imshow(a);
[r c] = ginput(4); %r rows-c columns-ginput(4) number of selected ponits are 4
BW = roipoly(a,r,c);
[R C] = size(BW);
for i = 1:R for j = 1:C if BW(i,j) == 1 % 1 means white out(i,j) = a(i,j); else out(i,j) = 0;% 0 means black end end end
prop = regionprops (out)
figure; subplot (1,3,1); imshow(a); title('Original image'); subplot (1,3,2); imshow(BW); title('selected area'); subplot (1,3,3); imshow(out,[]);title('output image');
But also, this kind of selection is manually and the properties of the selected area is unclear to me, specially when I couldnot scale the image?
Trust me, you will spend less time painting your disc than you would designing an image processing algorithm to handle exceptionally poor images. Paint the round part black and paint the ends of the lifters some bight non-sand color like white or bright green.
See my File Exchange for demos on image segmentation and color segmentation.
You'll see how to crop the region and redisplay it, which has the effect of scaling/magnifying it. You'll also learn how to segment the regions and measure things like area and perimeter and color/intensity.
Thank you sir, for your answer. yes, I already planned to change the painting for the extension of the expriments. But, for the current images I have I am also trying to make use of Matlab with such case....Thanks so much for your answer...
Please Sir, see the following photo....
I already wrote a code to detect patterns with white pixels in regions of interest. I have some questions: 1. how to set sacle for the main cylinder inorder I can relate the area of the region of interset to the acyual cylinder area?...for example diameter is known to be 50cm.
2. how can I read more than 1 photo (may be 100) with the same code to save time?
3. is there a way to maesure the angle from the center to the lifter where it is empty (no material)?
I don't know what the "sacle" is. If you want the convex hull, you can use bwconvhull(BW, 'union'). Then you can find the centroid if you want that.
Until you can get your disc repainted, I suggest you just use impoly() or roipolyold() to hand-draw the lifter regions.
2. There are code samples for processing a bunch of files in the FAQ: http://matlab.wikia.com/wiki/FAQ#How_can_I_process_a_sequence_of_files.3F
Thanks for your answers..it is really helpfull for me
sorry for some spelling mistakes... I meant set a Scale for the cylinder....that means I want to define the real dimensions of the cylinder....like in ImageJ software...I can draw a line (which is the diameter of the cylinder) and then scale it to its real value 50cm and then ImageJ relate every thing to this length.....
Can you please check this simple code (the problem is explained down):
*****code*******
for k = 1:2
jpgFileName = strcat('image', num2str(k), '.jpg');
if exist(jpgFileName, 'file')
a = imread(jpgFileName);
else
fprintf('File %s does not exist.\n', jpgFileName);
end
% %%%%%%%%%%Total cylinder pixel area %%%%%%%%%%%%
b = 322696; % from real dimension inner cylinder only using imageJ
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%Region 1 %%%%%%%%%%%%%%%
c = [15 7 9 14 68 55 68];
r = [252 306 357 381 368 315 253];
BW_1 = roipoly(a,c,r); %BW is just apart of the image
[C R] = size(BW_1);
for i = 1:C
for j = 1:R
if BW_1(i,j) == 1 % 1 means white
out_1(i,j) = a(i,j);
else
out_1(i,j) = 0;% 0 means black
end
end
end
d_1 = nnz(out_1); % non zeros
Area_1 = (d_1/b)*1963.5;
end
***********problem************
the problem I need Area_1 to be a matrix of the number of the number of image files being processed. Thanks
Before the loop just set a counter:
filesProcessed = 0;
Then right after you call imread(), increment it
filesProcessed = filesProcessed + 1;
then I guess you could set Area_1 to be filesProcessed, but I'm not really sure Area_1 would be a good name for the number of files that were processed, plus I don't know who Area_1 would be a matrix (2-D array) if it was just the number of files being processed.
no Sir., may be you have missunderstanding with my problem. Area_1 is the area of a specific region selected by the ROIPOLY in each image file so it should be a matrix of values equals to the number of files processed. Thanks alot I think I can handel it, thanks again for your interesting to help me with my problem. I will cite your file exchange weblink in my work (but it seems it return to name" Image Analyst" I donot know do you perefer this name for citing or you can give your real name?). and sure I will be back for you any question maybe you can help. Wish you a very happy new year
You said "I need Area_1 to be a matrix of the number of the number of image files being processed. " A matrix is a 2D array and I already saw that you were using that equation for one of them so I figured the second column would be the "number" like you asked for. But now it seems like you just want a row or column vector (1-D array) rather than a matrix. To get that, simply index Area_1 with filesProcessed. Don't use k because some k's may be skipped if there is no image for that k.
Area_1(filesProcessed) = (d_1 / b) * 1963.5;
You don't need to credit me specifically in your work but maybe you can just say something like "I wish to thank the volunteers in the MATLAB Answers forum for their helpful guidance and suggestions" or something similar.

Accedi per commentare.

Community Treasure Hunt

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

Start Hunting!

Translated by