how to create image from text file data.?

조회 수: 3 (최근 30일)
Lalit Patil
Lalit Patil 2012년 11월 22일
This is the text file i have generated.. I want to create image from it.. It will be binary image..
clc;
clear;
fileID = fopen('patil142.txt');
C = textscan(fileID, '%f32 %f32');
fclose(fileID);
x=cell2mat(C(:,1));
y=cell2mat(C(:,2));
x=x';
y=y';
I am able to read it only but don't know how to create image..?
  댓글 수: 4
Walter Roberson
Walter Roberson 2012년 11월 22일
The text file you linked to has x running 1 to 480, but y in the range 333 to 340, and has no 0's in it. If you are hitting 0 then either there is a problem in the reading or you are reading different data than you linked to.
Lalit Patil
Lalit Patil 2012년 11월 22일
sorry, i forget to upload new text file that contains 0's at somewhere..
scatter(x,y) shows plot and i want image. and the second column contains pixel intensities, so, 0 means nothing will be showed in image..
only positive integer values will be shown in image..

댓글을 달려면 로그인하십시오.

채택된 답변

Image Analyst
Image Analyst 2012년 11월 22일
Try this:
maxRows = max(y);
maxCols = max(x);
binaryImage = false(maxRows, maxCols);
for k = 1 : length(x)
row = int32(y);
col = int32(x);
binaryImage(row, col) = true;
end
  댓글 수: 14
Lalit Patil
Lalit Patil 2012년 11월 22일
편집: Lalit Patil 2012년 11월 22일
Yes this is the thing which i want.. Now the problem get solved...
Walter Roberson
Walter Roberson 2012년 11월 22일
Which version? The one that skipped those rows?

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Get Started with Image Processing Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by