Asked by Muhammad
on 17 Sep 2013

Hi all

Hope you are keeping good and enjoying a lot. i contoured some region of a image using imfreehand. i want to caculate the volume of every pixel inside the contour. but the information i have get in pixels[X and Y coordinate values are in pixel] and Z coordinate is thickness of the image which is in cm. i need to convert the pixel to cm to get the volume of the each pixel. is there any formula or any suggestions???

but for the whole image i have voxel size information as below. voxel size [Y=0.09cm, Y=0.09cm, Z=0.18cm].will this helpful.

any help is appreciated in advance.

Answer by Walter Roberson
on 17 Sep 2013

Muhammad
on 17 Sep 2013

Image Analyst
on 17 Sep 2013

How did you find this workbook?

Can't you just plug the x and y into polyarea() to get the area in pixels, then multiply by 0.09^2 to get the area in cm^2?

Muhammad
on 18 Sep 2013

Dear Dr. i am sending you my 2 pushbuttons program.which will tell how i created that workbook. 1 pushbutton is to contoure and other is to creat Excel sheet. please guide me about this. is this right or wrong way? and how can we calculate the volume of single pixel? as you know single pixel is a voxel because if its its coordinates are (x,y, thickness). if i say i want Volume of each Voxel inside the contoure region then it will better. hoping for early response;

if true

function Contourpushbutton_Callback(hObject, eventdata, handles)

% imfreehand

h=imfreehand(gca,'closed',0);

% waitfor(h);

pos = getPosition(h);

% sz = size(handles.listbox1);

handles.output = hObject;

index = get(handles.listbox1,'value');

sz = size(handles.I{index});

handles.maskedImage = poly2mask(pos(:,1), pos(:,2), sz(1), sz(2));

guidata(hObject, handles); %use this line to save the handles structure during callbacks

end

if true

% --- Executes on button press in ExcelPushbutton.

function ExcelPushbutton_Callback(hObject, eventdata, handles)

[X, Y] = find(handles.maskedImage ~= 0);

data=[Y,X];

Z = repmat(0.18,[length(X),1]);

A=times(X,Y);

volume=times(A,Z);

[FileName,PathName] = uiputfile('*.xls','Save data to spreadsheet');

Data=[X,Y,Z,volume];

xlswrite([PathName '/' FileName],Data);

end

Sign in to comment.

Opportunities for recent engineering grads.

Apply Today
## 3 Comments

## mohd akmal masud (view profile)

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/87470-how-to-convert-pixel-to-cm#comment_513098

## Walter Roberson (view profile)

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/87470-how-to-convert-pixel-to-cm#comment_513099

## mohd akmal masud (view profile)

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/87470-how-to-convert-pixel-to-cm#comment_513143

Sign in to comment.