필터 지우기
필터 지우기

Convert matrix number into png image

조회 수: 16 (최근 30일)
Geppo Batt
Geppo Batt 2012년 4월 15일
Hello i'm new on package "Image Processing Toolbox". I have a matrix of number ( http://dl.dropbox.com/u/59868217/matlab.mat) obtained by this script ( http://dl.dropbox.com/u/59868217/show_im_GR.m) I would be able to convert an image to grayscale or black and white. Possibly in png format.
How can I do ?

채택된 답변

Image Analyst
Image Analyst 2012년 4월 15일
I looked at your m-file. You get your data like this:
A = fread(fid,size,'*uint16');
img = reshape(A,width,height); %ok-->poi trasponi
Did you know you can get the 2D matrix directly like this:
img = fread(fid, [width, height], '*uint16');
% It will be a 2D array after this.
No reshaping will be necessary. Anyway, to get it into PNG format you have to save it out to disk as a PNG format image file because when it's in MATLAB it's simply an array of numbers and format doesn't really apply.
baseFileName = 'My matrix.png';
fullFileName = fullfile(folderName, baseFileName);
imwrite(img, fullFileName);

추가 답변 (1개)

Geppo Batt
Geppo Batt 2012년 4월 15일
but the png file is completely black, while if use figure,image(img);colormap(gray); title(filename); obtained this image : http://dl.dropbox.com/u/59868217/untitled.jpg
  댓글 수: 5
Geppo Batt
Geppo Batt 2012년 4월 17일
ok perfect, thank you very much. you saved me. the last question minvalue and maxvalue what does they for ?
Image Analyst
Image Analyst 2012년 4월 17일
I just called them to see if you had integer or floating point values and if they were in the range 0-255, 0-1, or something else. which might cause me to call mat2gray() or uint8().

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

카테고리

Help CenterFile Exchange에서 Image Processing and Computer Vision에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by