You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
i know the scale but when i use imagesc function the image doesnt show me the right size of my spot. what am i doing wrong?
3 views (last 30 days)
Show older comments
clear all;
close all;
Scale = 29.4/64; % Pixelscale of the image
[FileName, PathName] = uigetfile({'*.txt','PHASICS Txt File';'*.*', 'All Files (*.*)'},'Pick a file');
PhaseFile = fullfile(PathName,FileName);
PhaseData=importdata(PhaseFile,'\t'); % Read header less tab delimited txt file[Ny, Nx] = size(PhaseData);
[Nx, Ny] = size(PhaseData);
figure
imagesc(PhaseData); % Plot the data
Accepted Answer
Image Analyst
on 10 Jan 2022
PhaseData is structure. you need the Data field
theImage = PhaseData.Data;
19 Comments
Image Analyst
on 11 Jan 2022
When you browsed to a file and selected it, what was the name of that file? Please attach that file with the paperclip icon.
Image Analyst
on 12 Jan 2022
This seems to work
Scale = 29.4/64; % Pixelscale of the image
% [FileName, PathName] = uigetfile({'*.txt','PHASICS Txt File';'*.*', 'All Files (*.*)'},'Pick a file');
% PhaseFile = fullfile(PathName,FileName);
PhaseFile = 'EXPORT PHA 170,0.5C,100,110,120 nJ, 20mmmin_0001.txt'
PhaseData=importdata(PhaseFile,'\t') % Read header less tab delimited txt file[Ny, Nx] = size(PhaseData);
[Nx, Ny] = size(PhaseData)
figure
imagesc(PhaseData); % Display the data
Is there still a problem?
Sobia Rehman
on 12 Jan 2022
The height of my structure shown here is 30, although actual height is 10 and the scale along x axis and y axis is the pixel count? or micrometer etc?
Image Analyst
on 12 Jan 2022
It's the pixel count. If you want the axes to show some other units, you can change the tick labels with 'XData' and 'YData' in imshow().
PhaseFile = 'EXPORT PHA 170,0.5C,100,110,120 nJ, 20mmmin_0001.txt'
PhaseData=importdata(PhaseFile,'\t'); % Read header less tab delimited txt file[Ny, Nx] = size(PhaseData);
[rows, columns] = size(PhaseData)
fovy = 10;
fovx = fovy * columns / rows
imshow(PhaseData, [], 'XData', [0, fovx], 'YData', [0, fovy]); % Display the data
caption = sprintf('Micrometers (%d pixels along x)', columns);
xlabel(caption)
caption = sprintf('Micrometers (%d pixels along y)', rows);
ylabel(caption)
axis ('on')
Sobia Rehman
on 17 Jan 2022
Its working.
But this image shows it is 1.5 um but actually its around 14-15 um.
What can be the reason?
Image Analyst
on 17 Jan 2022
I guess your scale (calibration factor) is wrong. See attached spatial calibration demo and integrate it into your code.
Sobia Rehman
on 19 Jan 2022
Thanks Heaps!!
I will work on that but I want do one more task at the end. Once I get the image with exact dimentions I want to plot a grapgh for those dimentions (x and y) with third variable (Refractive index) in Imagesc to get a colored image at the end. Can you please guide how to assign x and y for dimentions and then tis specific plot?
Image Analyst
on 19 Jan 2022
To get a line plot of x vs your third variable (let's call it z), you can use hold on. Then use rescale() to scale your third variable between 1 and the number of rows. Basically it would overlay a line plot over the image so you'd have z vs x and y would not be involved.
I'm not exactly sure what you want. So do you have a z value for every (x,y) pair? That would be an image or a surface. You can't put that over your original image without obscuring your original image. I suggest you use surf() or imshow() to show your z vs. (x,y) data.
Sobia Rehman
on 15 Feb 2022
Hi again,
I want know one point.
I want to get the simplest method for this. If we have an image in pixel count and we know the scale of pixel and we want to assign the pixel along x axis as x cordinates and the pixel along y axis as y cordinates and then want to plot it according to the scale. what can be the simplest code for that?
Image Analyst
on 15 Feb 2022
@Sobia Rehman not sure what you mean but let me reqord it more precisely and see if that's what you mean. You have a distance in pixels, and you have a spatial calibration factor in (real world units) per pixel. Now you want to plot the x and y, which you have in pixels, in real world units. Is that it? If so, lets say your units are millimeters and you have a variable called mmPerPixel, and vectors xInPixels and yInPixels in units of pixels. So you'd just convert and then plot
xInMm = xInPixels * mmPerPixel;
yInMm = yInPixels * mmPerPixel;
plot(xInMm, yInMm, 'b-', 'LineWidth', 2);
grid on;
xlabel('X in mm', 'FontSize', 20);
ylabel('Y in mm', 'FontSize', 20);
title('Y vs X in mm', 'FontSize', 20);
Sobia Rehman
on 16 Feb 2022
I have attavhed two files.
when i start with
clear all;
close all;
Scale = 29.4/64; % Pixelscale of the image
[FileName, PathName] = uigetfile({'*.txt','PHASICS Txt File';'*.*', 'All Files (*.*)'},'Pick a file');
PhaseFile = fullfile(PathName,FileName);
PhaseData=importdata(PhaseFile,'\t');
The above lines of the code is to call the file and scale is mentioned.
Then I start with
[Nx, Ny] = size(PhaseData); This is to find the number of rows and columns
If i write next in code
imagesc(PhaseData); This displays me the image of PhaseData and along x axis and y axis numbers are shown which is actually xcordinates and ycordinates in pixel count. My question is how to assign the x cordinates and y cordinates in pixels first and then convert it to mm according to the scale.
In last comment you have mentioned xInPixels but i dont know how to assign values to this xInPixels.
I hope my question is clear. I am stuck with this issue from many days. It will be great if you can help me out from this.
Many Thanks
Image Analyst
on 16 Feb 2022
You can use imshow():
XData = [0, Nx] * Scale;
YData = [0, Ny] * Scale;
imshow(PhaseData, 'XData', XData, 'YData', YData);
axis('on', 'image')
This will make the axis read out in calibrated, real world units instead of pixels.
Sobia Rehman
on 16 Feb 2022
This gives me an image like this
Can you please have a look. Thanks for your time and efforts.
Sobia Rehman
on 16 Feb 2022
Finally I have got this using this code
clear all;
close all;
%nBulk = 1.4536;
Scale = 29.4/64; % Pixelscale of the image
[FileName, PathName] = uigetfile({'*.txt','PHASICS Txt File';'*.*', 'All Files (*.*)'},'Pick a file');
PhaseFile = fullfile(PathName,FileName);
PhaseData=importdata(PhaseFile,'\t'); % Read header less tab delimited txt file[Ny, Nx] = size(PhaseData);
[Nx, Ny] = size(PhaseData);
XData = [0, Nx] * Scale;
YData = [0, Ny] * Scale;
imagesc(XData, YData, PhaseData);
This shows me the picture now in real life units.
Thanks heaps for your help.
Image Analyst
on 16 Feb 2022
You must have floating point image outside the range of 0-1. So try it this way:
XData = [0, Nx] * Scale;
YData = [0, Ny] * Scale;
imshow(PhaseData, [], 'XData', XData, 'YData', YData);
axis('on', 'image')
More Answers (0)
See Also
Categories
Find more on Convert Image Type in Help Center and File Exchange
Tags
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 (한국어)