how to convert a double matrix image to a unit8 matrix ?

조회 수: 25 (최근 30일)
Mariem Harmassi
Mariem Harmassi 2013년 3월 8일
댓글: Bruno Aravena Pérez 2022년 4월 29일
Hi everybody :) I have an image ,a matrix with values between -0.0934 and 0 and i want to convert it to unit8 matrix with values between 0 ans 255.

채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2013년 3월 8일
편집: Azzi Abdelmalek 2013년 3월 8일
A=imread('yourimage')
B=uint8(A)
EDIT
d=linspace(min(im(:)),max(im(:)),256)
im1=uint8(arrayfun(@(x) find(abs(d(:)-x)==min(abs(d(:)-x))),im))
  댓글 수: 4
Mariem Harmassi
Mariem Harmassi 2013년 3월 8일
yes i tried uint8 it was just an error
Azzi Abdelmalek
Azzi Abdelmalek 2013년 3월 8일
편집: Azzi Abdelmalek 2013년 3월 8일
Try this
%If im is your image
d=linspace(min(im(:)),max(im(:)),256)
im1=uint8(arrayfun(@(x) find(abs(d(:)-x)==min(abs(d(:)-x))),im))

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

추가 답변 (1개)

Image Analyst
Image Analyst 2013년 3월 8일
You can use the mat2gray() function:
image8Bit = uint8(255 * mat2gray(floatingPointImage));
It will scale your values to the range 0-255.
  댓글 수: 10
Juan Manuel Miguel
Juan Manuel Miguel 2020년 8월 6일
Thank you, it was perfect for me!!

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

Community Treasure Hunt

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

Start Hunting!

Translated by