필터 지우기
필터 지우기

issue in converting matrix to rgb image

조회 수: 2 (최근 30일)
PRACHI Sood
PRACHI Sood 2020년 4월 3일
댓글: PRACHI Sood 2020년 5월 12일
I was trying to replace pixel values by their corresponding 3x3 non overlapping block. since the output matrix was of type double I converted it to uint8 type.
But when I displayed the image in the figure window it was gray instead of coloured image . I tried cat(3, gray, gray, gray) but image is still colourless.
What did I do wrong?
img= imread('C:\Users\prach\MATLAB programs\Lenna_(test_image).png');
new = blockproc(img, [10 10], fun);
new1= uint8(new);
imshow(new1)
rgbnew= cat(3, new1, new1, new1);
imshow(rgbnew)
  댓글 수: 7
Walter Roberson
Walter Roberson 2020년 5월 11일
sounds like you are using a slightly older version of MATLAB that does not permit multiple dimensions. In that case as long as the image grayscale, median(block_struct.data(:))
But if you are dealing with rgb then it gets a bit messier,
median(reshape(block_struct.data,[],1,3),1)
PRACHI Sood
PRACHI Sood 2020년 5월 12일
@Walter Roberson
The median(block_struct.data(:)) worked perfectly. Thankyou very much.

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

답변 (1개)

Image Analyst
Image Analyst 2020년 5월 10일
You need to use imsplit() to get the individual color channels, and then process them and combine them with cat(3).
  댓글 수: 4
Image Analyst
Image Analyst 2020년 5월 11일
The blockproc_color_means.m demo gives this image. Is it like you want?
PRACHI Sood
PRACHI Sood 2020년 5월 12일
Apologies for the incomplete information. Attaching the .m file and the image.
Yes, the output images shown in your last comment as output of blockproc_color_means.m is my desired output. I will go through the list of demos you have provided. Thankyou very much.

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

Community Treasure Hunt

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

Start Hunting!

Translated by