Error While Saving the Raw data into Binary Image.
古いコメントを表示
Hello Everyone, I hope you are doing well. I have the code which make the data into Image format.
But the main issue with this code is that, When the same values of data comes it gives the error here is the error.
As i attached the 2 dataset below. The code works fine on dataset2.mat
While when we run it into dataset1.mat it gives the error.
Error using matlab.internal.math.interp1
Sample points must be unique.
Error in interp1 (line 188)
VqLite = matlab.internal.math.interp1(X,V,method,method,Xqcol);
The following is the code which i used
[numImages, lenImage] = size(Dataset1000);
% ImageSize
for imNum = 1:numImages
imData = Dataset1000(imNum,:); % get pattern
dataset=imData;
x=1:numel(dataset);%this is what you did implictly
y=dataset;
resolution=1000;
X=linspace(min(x), max(x) ,resolution);
Y=linspace(min(y), max(y) ,resolution);
% determine index in X of each x, likewise for y (note that the coordinates
% are flipped for the y-direction in images).
ind_x=interp1(X, 1:numel(X) ,x,'nearest');
ind_y=interp1(Y,numel(Y):-1:1,y,'nearest');
%compute linear index
ind=sub2ind([resolution resolution],ind_y,ind_x);
% create the image
IM=zeros(resolution,resolution);
IM(ind)=1;
% Since you apparently want a dilation, apply it before displaying the
% image.
SE=strel('disk',2);
im=imdilate(IM,SE);
end
回答 (1 件)
Walter Roberson
2022 年 10 月 17 日
0 投票
We talked to you about this already. Your min x and max x are the same so your linspace is all the same value.
There is no way to rescue the situation with a small code tweak. You need to go back and rethink what you are doing.
Have you considered using improfile()? It automatically switches between interpolation over x or over y to get the best results.
8 件のコメント
Stephen john
2022 年 10 月 17 日
Stephen john
2022 年 10 月 17 日
Walter Roberson
2022 年 10 月 17 日
No, sorry, you will need to give up on the task as you have currently defined it.
You are trying to ask the question "what is the unique y value for this x value", and that is going to fail for vertical lines, as such lines have several simultaneous y values for some x value. So you need to not ask that question at least for vertical lines. It probably is not a great idea to ask that question for lines that are almost vertical, such as a one pixel change in x and a 400 pixel change in y.
improfile does 2d interpolation between two endpoints, returning the interpolated values and also the x and y coordinates interpolated at. It automatically chooses whether to increment along x or along y to give the best results.
Stephen john
2022 年 10 月 17 日
Walter Roberson
2022 年 10 月 17 日
To draw lines into an array use Computer Vision insertShape() or use the File Exchange contributions for Breshenham's Line Algorithm
Stephen john
2022 年 10 月 18 日
Stephen john
2022 年 10 月 18 日
Walter Roberson
2022 年 10 月 18 日
Computer Vision has insertShape and insertText. Between the two they can create any line graph (surfaces are harder)
カテゴリ
ヘルプ センター および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!