how to convert back to tiff image
조회 수: 15 (최근 30일)
이전 댓글 표시
Hi all,
I have written a code that converts an image to a three dimentional matrix and then fills the surrounding area with black color until it becomes a 1000*1000*3(for jpg) or 1000*1000*4(for tif) pixel matrix. In order to make sure that the code is working properly, I have to see the final picture. so I convert it back to the picture using imwrite. The problem is that although both jpg and tif formats are in uint8 class of data type,imwrite works only for jpg format. but for tif format, it will convert back to a grey scale picture. anyone can help fix the problem for tif format?
I could only attach the jpg file. I take it as imageIn.
you can make a tif format out of this file using paint windows app.
object = [1000 1000];
here is the code I wrote :
function imageOut = imageX(imageIn,object );
Image = imread(imageIn );
spaceRow = size(object,1)-size(Image,1 );
spaceAbove = round(spaceRow/2 );
spaceBelow = spaceRow - spaceAbove ;
Image1 = [255.*ones(spaceAbove,size(Image,2),size(Image,3));Image;255.*ones(spaceBelow,size(Image,2),size(Image,3 ))];
spaceColumn = size(object,2)-size(Image,2 );
spaceRight = round(spaceColumn/2 );
spaceLeft = spaceColumn - spaceRight ;
imageOut = [255.*ones(size(Image1,1),spaceLeft,size(Image,3)),Image1,255.*ones(size(Image1,1),spaceRight,size(Image,3 ))];
imwrite(imageOut,'imageOut.jpg '); %if the file is a tif format I am gonna write imwrite(imageOut,'imageOut.tif') instead.
end
댓글 수: 0
답변 (1개)
Image Analyst
2017년 12월 26일
It does not look like imageOut is uint8. Cast it to uint8 and try again.
Also, object is not used so you can remove it from the input argument list.
Do not use Image as the name of your variable. We like to avoid using built-in function names for variable names, even though MATLAB is case sensitive. One typo (i for I) and you could have a hard time tracking down the problem.
댓글 수: 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!