You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
how i can get the profile of pixel value in dicom
6 views (last 30 days)
Show older comments
hello,
I am trying to plot the pixel value in profile of dicome image, i try the solution mentioned in previuse questions but it not working?
maybe for dicome there is certain code labeling?
Accepted Answer
Image Analyst
on 8 Oct 2021
Do you mean dicom? As in from a .DCM image file? Did you try using improfile()?
35 Comments
Walter Roberson
on 10 Oct 2021
What happens when you try?
improfile() does not care where the image came from: you have to have already read in and displayed the image to use improfile()
Maram Othman
on 11 Oct 2021
i use the following
D= dicominfo('RD_QAkernel-10MV_K_10.dcm');
grayImage = dicomread('RD_QAkernel-10MV_K_10.dcm');
dicomdisp('RD_QAkernel-10MV_K_10.dcm');
[X, map] = dicomread('RD_QAkernel-10MV_K_10.dcm');
montage(X, map, 'Size', [2 5]);
grayImage = dicomread('RD_QAkernel-10MV_K_10.dcm');
grayLevel = grayImage(512, 512);
dinfo = dicominfo('RD_QAkernel-10MV_K_10.dcm');
spacing = dinfo.PixelSpacing;
per_pixel_area = spacing(2) * spacing(2);
num_white_pixels = nnz(binarized_img);
total_white_area = num_white_pixels * per_pixel_area;
dicomrd('RI_K_10_165650.467000.dcm');
dicomdisp('RI_K_10_165650.467000.dcm');
improfile('RD_QAkernel-10MV_K_10.dcm');
%what i got is black image
Maram Othman
on 11 Oct 2021
Edited: Image Analyst
on 11 Oct 2021
D= dicomread('RD_QAkernel-10MV_K_2.dcm');
I = dicomread('RD_QAkernel-10MV_K_2.dcm');
dicomdisp('RI_Tria_10MV_123904.080000.dcm');
c = improfile(I);
figure
subplot(2,1,1)
plot(c)
Error in mn1 (line 5)
c = improfile(I);
Walter Roberson
on 11 Oct 2021
you cannot improfile() a file name.
I predict that the image you read is not rgb or 2d.
Image Analyst
on 11 Oct 2021
Edited: Image Analyst
on 11 Oct 2021
What does this say in the command window:
D= dicomread('RD_QAkernel-10MV_K_2.dcm');
whos D
I = dicomread('RD_QAkernel-10MV_K_2.dcm');
whos I
I2 = dicomread('RI_Tria_10MV_123904.080000.dcm');
whos I2
Maram Othman
on 11 Oct 2021
these are well solved in the command, where dicom information listed and i can access it, these are two different dcm images that i was trying to work on them,
what i actuauly need is :The pixel values at the center of the raw image
i get the raw data as 3650*3650 values for graylevel which will be correlated with dose delivered through this beam
so, I could not plot pixel, nethier how to evaluate the The pixel values at the center of the raw image such as 3*3 pixels in the center of the image?
Image Analyst
on 11 Oct 2021
OK, I'm probably going to bow out since you're not going to answer my question about using whos. Good luck. Call tech support if you need an immediate answer.
Walter Roberson
on 11 Oct 2021
We need:
- size(I)
- class(I)
- A complete copy of the error message, indicating what MATLAB thinks the problem is with calling improfile()
Maram Othman
on 11 Oct 2021
ok, Now it work, thank you very much !
so this is how the profile I get
I want to normalize the pixel value to the value of its central region with 3*3 pixel or 5*5 pixel
and how to do it in raw data type?
Walter Roberson
on 11 Oct 2021
whos is a MATLAB command. For example,
IMG = imread('cameraman.tif');
load handel
whos
Name Size Bytes Class Attributes
Fs 1x1 8 double
IMG 256x256 65536 uint8
y 73113x1 584904 double
Notice how it gives the name of the variable, the size of the variable, and the Class of the variable. It is difficult for us to assist you without knowing that kind of information about your variables.
Walter Roberson
on 11 Oct 2021
What does it mean to you to "normalize the pixel value to the value of its central region with 3*3 pixel or 5*5 pixel" ?
If you want to do median filtering then use medfilt2()
Maram Othman
on 17 Oct 2021
@Walter Roberson for meadian it will change the whole data within the dicom image, the image is dicom with chrome2 type, i mean about the mean pixel value of 3*3 pixel sizze, is how to iput or specify the coordinate exactly to take 3*3 pixels?
if for example the whole image size is 1024*1024 pixel size then its cetral 512 then i take like matrix around the central by 3 *3, and do it as mask to apply for the pixels neighbour?
i was thinking if this would be the road to do it? can you comment?
many thanks for your help, really appreciate it
Image Analyst
on 18 Oct 2021
@Maram Othman To get the mean of the 3 x 3 window around the single pixel at the center of the image at (512, 512), do this:
m = mean2(grayImage(511:513, 511:513))
To do that over the whole image you'd do
kernel = ones(3)/9;
m = conv2(double(grayImage), kernel, 'same');
Maram Othman
on 10 Nov 2021
@Image Analyst thank you i try it and it work, now i will ned to plot the matrix of 1024x1024 but with normalize all its value to acertain equation where each pixel vaule i need to convert accordning to the following equation =( 2^16- gray level in eachpixel in matrix)/ constant (constant which value i have from DICOM header)
so, how i will do this? and many thanks in advance,
Walter Roberson
on 10 Nov 2021
NewValue = (2^16 - double(YourImage))./TheConstant
Afterwards you might be wanting to change datatype.
Maram Othman
on 10 Nov 2021
@Walter Roberson thank you very much,
so, Now I will try it, but to make my question undertstandable, the original matrix of graylevel when i polt it, it give me the folloing graph,
so, what I actually want is to renormalize the gray value to have that gaph flip upside down,
so, is it will work with that value of equation? if so, i want to recal the constant value from the dicom header, how to implement this in the syntax?
Maram Othman
on 10 Nov 2021
I look at that link, but i don't think rescale the slope will help! because the information is a matrix that along the image, and i just want to rescale the pixel value to be eble to plot in 2D, as i do this analysis in excel but i want to do it in matlab to try visulaize the matrix pixel value \fter rescaling
I hope you get my question
thank you
Walter Roberson
on 10 Nov 2021
What is the name of the DICOM attribute that you need to read from the header?
Also, please confirm that you will be needing to divide by the value, rather than multiplying by the value.
Maram Othman
on 10 Nov 2021
when I open dicom in imagJ, the dicom header provide this for the value:
0021,1002 ---: 0.30318 (so it has no name but the code number is (0021,1002)
when i do dicominfo in matlab, it provide the value with : (field = private_0021_1002) and (value=0.30318)
in dicomread provide it as:
Location Level Tag VR Size Name Data
0001076 0 (0021,1002) DS 8 bytes - Private_0021_1002 [0.30318 ]
I will need to dividee the equation with it
thank you
Walter Roberson
on 10 Nov 2021
I find a couple of different places that define that tag. GE defines it as PET raw_data_size (unsigned long). Someone defines it as SliceNumber (within a PET context) . I do not seem to find any definitions as a floating point number, but it is possible (as it is in the Private Tags range.)
Walter Roberson
on 10 Nov 2021
Anyhow,
dinfo = dicominfo(filename);
Private_0021_1002 = dinfo.Private_0021_1002;
YourImage = dicomread(dinfo);
NewValue = (2^16 - double(YourImage))./Private_0021_1002;
Maram Othman
on 15 Nov 2021
Hello, again, @Walter Roberson
I want to ask somthing, now, I have number of images where I need to plot the profile of each image but I want to appear all the plot together in one figure,
I try to plot for every image but it does not work with me to keep the profile figure of first image and add the new profile, thus, i do the code as follow:
\\\
info = dicominfo('RI_1200dr100mu_163320.235000.dcm');
Y = dicomread(info);
Private_0021_1002 = dinfo.Private_0021_1002;
YourImage = dicomread(dinfo);
NewValue = (2^16 - double(YourImage))./Private_0021_1002;
imshow(NewValue);
improfile();
\\\
this I should apply for each image separately, but I want to apply to all images while plotting the profile after each image matrix correction, So how I can do that?
many thank in advance>
Walter Roberson
on 15 Nov 2021
There are a few different situations:
- if you are always taking the profile along the same line, and that line is exactly horizontal or exactly vertical, and you would be fine with it lining up exactly with existing data: then in this case, the profile can be taking by just indexing NewValue at the appropriate rows or columns.
- if you are always taking the profile along the same line, and that line is not exactly horizontal or exactly vertical, or is but has to be "between" two existing data lines, then improfile() works by using interp2(). The question then becomes which coordinates to interpolate at. A typical way to handle that is to compare the difference in X coordinates of the endpoints, against the difference in Y coordinates of the endpoints, and to choose the longer axes to be the one to use consecutive locations along, and linspace() the other coordinate according to the length of the longer axes.
- If you are not always taking the profile along the same line, such as if you are taking a profile between opposite "corners" but the corners are not always exactly in the same place, then first we need to figure out how to automatically detect whatever it is you are measuring.
Maram Othman
on 16 Nov 2021
Yes, exactly, as you mention "
- if you are always taking the profile along the same line, and that line is exactly horizontal or exactly vertical, and you would be fine with it lining up exactly with existing data: then in this case, the profile can be taking by just indexing NewValue at the appropriate rows or columns."
in this way, I need it at the central of pixel raw as total matric [1024x1024] then central should be within [512x512]
how to ut this indexing? Many thanks!
Maram Othman
on 16 Nov 2021
I try to do this command:
figure;plot(NewValue(512,:))
it gives me a line profile , then if I save all the corrected matrixs of a set of images, then go the matrix table and choose the raw number 512, to plot it profile will work to add many profile together or there is another simple or short way to do it?
Walter Roberson
on 16 Nov 2021
Extracting the center of a matrix that might be an odd size or might not be divisible by 4, turns out to be a bit complicated. I do not assume that your matrix will always be exactly 1024 x 1024 in the below.
Not all of the below steps need to be done, or at least not as verbosely: the below goes through and displays all of the calculation results so that they can be checked for reasonableness.
Design decisions:
- if the edge is an odd size, then the "center" should be an odd size, and there should be even amounts before and after the center
- if the edge is an even size, the center should be exactly half of that size. If it is possible to put the same size margin before and after the center then do so, but otherwise start the center one further onwards. For example if the edge were length 10, then the center is length 5, leaving 5 units on the outside that has to be distributed between before and after, but that cannot be done equally on the two sides so use 3 before, then the 5 for the center, then 2 afterwards.
NewValue = randi(256, 598, 769, 'uint8'); %for testing purposes
[R, C, ~] = size(NewValue)
R = 598
C = 769
NCR = ceil(R/2)
NCR = 299
NCC = ceil(C/2)
NCC = 385
BeforeCR = ceil((R - NCR)/2)
BeforeCR = 150
LastCR = BeforeCR + NCR
LastCR = 449
BeforeCC = ceil((C - NCC)/2)
BeforeCC = 192
LastCC = BeforeCC + NCC
LastCC = 577
NewCenter = NewValue(BeforeCR+1:LastCR, BeforeCC+1:LastCC, :);
AfterCR = R - LastCR
AfterCR = 149
AfterCC = C - LastCC
AfterCC = 192
Maram Othman
on 16 Nov 2021
Edited: Image Analyst
on 16 Nov 2021
Well, yes I tried your solution, which provides a central matrix that takes the information inside the central matrix size with the dimention of R,C. I think this solution will help me when I want to do the mean average value of central matrix that represented within rectangular or box dimention. and at certain point of my work I need to do it.
However, what I mean in plotting the profile of central pixel value of the matrix is like if I draw a horizontal line across the image itself to find out the pixel values along it.
For example i do the following:
figure;plot(NewValue_1000_25(512,:)) where the profile is for one raw in the central horizontal raw,
I want to know a way to plot different images profile value in same graph, i try to export each image raw value og 512 into excel and plot it as series plotting as follow:
This way I need to do in matlab. I try to import again different images in matlab and do plotting but it does not work.
Where also, I try to do imagedisplay, then improfile(), when the image appears and I draw a line across its central, I got the profile but it represents the matrix value without normalizing it to constant value.
I repeat with introducing the NewValue of normalized constant and do the command of image display of newvalue where the profile was correct as it normalized, however trying to draw the horizontal line manually is not useful and can be deviated from central part where i have to study the gray value.
I hope my question is now clear, and many thanks @Walter Roberson
Image Analyst
on 16 Nov 2021
To make sure you draw across the center of the disk, find the center of the disk from your image, then have the user click once outside the disk, then draw a line from there through the center. Untested code:
mask = yourImage > someValue;
mask = bwareafilt(mask, 1); % Take largest blob only.
props = regionprops(mask, 'Centroid');
xCenter = props.Centroid(1);
yCenter = props.Centroid(2);
% Now ask user to click close to but outside the disk.
uiwait(helpdlg('Click outside the disk'));
[x1, y1] = ginput(1)
% Fit a line through
coefficients = polyfit([x1, xCenter], [y1, yCenter], 1)
% Then compute the other endpoint
deltaX = abs(x1-xCenter)
if x1 > xCenter
x2 = xCenter - deltaX
else
x2 = xCenter + deltaX
end
y2 = polyval(coefficients, x2)
% Now call improfile
xi = [x1, x2];
yi = [y1, y2];
profile = improfile(yourImage, xi, yi);
Maram Othman
on 25 Nov 2021
Hello, @Image Analyst
I tried what you suggest, however, in your code which value should be specify in this line:
mask = yourImage > someValue; >>>>>>which value? is it a pixel number in the matrix or the central value of the pixel?
//
mask = bwareafilt(mask, 1); % Take largest blob only.
//
then, in this point what you mean by this function:bwareafilt?
---
regrding completing here, I want to run the certian values exctract from number of images, so, how I can specify the variable to be extract from each image to be label in its name by image name?
for example, for image from 1 to 10
i want to exctract te matrix values with certian arbitrary values but, the name of variable or matrix can be set easly by image name/number?
thank you
Walter Roberson
on 25 Nov 2021
someValue should be a value that is the border between "background" and signal. At the moment, how do you judge what part of the image is part of the center that you want to measure, as compared to being part of the background that you do not want to measure?
Maram Othman
on 25 Nov 2021
I am considering a region of 400x400 pixel to be included inside the central part that I want to investigate,
for the value in this region I tried to do the mean2 function, but I also tried to do the following,
% for 3 image set I want to study the central od 400x400 pixel, then after the NewValue is rescaled I do:
x1=NewValue_1(400:700,400:700)
x2=NewValue_2(400:700,400:700)
x3=NewValue_3(400:700,400:700)
and for X2 image signal will contribute X3 signal, to find the relative difference of signal contribution,
signal=x2./x3
plot(signal)
More Answers (1)
yanqi liu
on 11 Oct 2021
Edited: yanqi liu
on 18 Oct 2021
clc; clear all; close all;
[X, map] = dicomread('US-PAL-8-10x-echo.dcm');
n = size(X, 4);
D=[];
for i=1:n
I = ind2rgb(X(:,:,:,i), map);
I = rgb2gray(I);
I = double(I);
D(:,:,i)=I;
end
figure; imshow(D(:,:,1));
[cx,cy,c] = improfile(D(:,:,1), [270 380], [130 330]);
hold on; plot(cx, cy, 'r-', 'LineWidth', 2)
figure; plot(c);
1 Comment
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)