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 次查看(过去 30 天)
显示 更早的评论
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
采纳的回答
Image Analyst
2022-1-10
PhaseData is structure. you need the Data field
theImage = PhaseData.Data;
19 个评论
Image Analyst
2022-1-11
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
2022-1-12
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
2022-1-12
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
2022-1-12
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
2022-1-17
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
2022-1-17
I guess your scale (calibration factor) is wrong. See attached spatial calibration demo and integrate it into your code.
Sobia Rehman
2022-1-19
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
2022-1-19
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
2022-2-15
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
2022-2-15
@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
2022-2-16
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
2022-2-16
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
2022-2-16
This gives me an image like this
Can you please have a look. Thanks for your time and efforts.
Sobia Rehman
2022-2-16
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
2022-2-16
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')
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Convert Image Type 的更多信息
标签
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!发生错误
由于页面发生更改,无法完成操作。请重新加载页面以查看其更新后的状态。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- 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)
亚太
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)