How we can maximize PSNR between RGB image and binary(0,1) image?

14 views (last 30 days)
Hi, I have one RGB image and i want to create binary image from that with maximum PSNR. How i can do that?
In another word, The goal we are pursuing here is to make the output black and white image look like
Most images are the original color image from a PSNR perspective

Accepted Answer

Yusuf Suer Erdem
Yusuf Suer Erdem on 15 Nov 2021
Converting segmented RGB images into GRAYSCALE form is really good idea to process them.
  14 Comments
DGM
DGM on 21 Nov 2021
You can certainly get a number, but again, what is the meaning of the comparison between these two images? The images are not remotely similar.
A = imread('peppers.png');
im2=imbinarize(A);
im2=uint8(im2);
b = psnr(A,im2) % it's a number
b = 8.0089
imshow(A); % the original RGB image
figure;
imshow(im2); % it's an approximately black RGB binary image
You mention trying to replicate imbinarize, but imbinarize doesn't do what you're describing. The closest might be the 'adaptive' method. If that's what you're after, just open up imbinarize() and read it. The private functions it calls should be in the toolbox directory.

Sign in to comment.

More Answers (3)

yanqi liu
yanqi liu on 18 Nov 2021
sir,may be use
if ndims(im) == 3
im = rgb2gray(im);
end
im = double(im2uint8(mat2gray(im)));
to get the same data type
  3 Comments

Sign in to comment.


Yusuf Suer Erdem
Yusuf Suer Erdem on 20 Nov 2021
I was not able to implement your codes into that probably psnr funtion only allows limited data types.
  1 Comment
mohammad nemat
mohammad nemat on 20 Nov 2021
It's worked for me. you should use psnr function from matlab with lowercase characters .

Sign in to comment.


Image Analyst
Image Analyst on 20 Nov 2021
I agree with what Yusuf and DGM said, especially DGM who came up with a clever solution. He should post it as his own answer so we can vote for it and award him reputation points. They asked why you think you need it and that it may be irrelevant. Even when DGM specifically asked you why you need it you didn't really answer and just said basically "I need it because I need it" which is a non-answer. PSNR is usually used in comparing compression techniques, not comparing a 24 bit image to a 1-bit image. So what will you do with the thresholds DGM came up with?
  2 Comments
Image Analyst
Image Analyst on 21 Nov 2021
OK, I'll try to explain what I was thining about. When DGM and I asked you why you need a threshold to "maximize PSNR between RGB image and binary(0,1) image", your answer was that the reason why was in the title which is that you need to "maximize PSNR between RGB image and binary(0,1) image". So that's why I said you basically said "I need it because I need it."
Let's look at it a different way. Let's assume I asked you "I need a doohickey. Can you make me a doohickey?" And you replied "Why do you need a doohickey?" And I just replied "I already told you why -- I need a doohickey!"
Alright here is a common scenario.
  1. Person Q says "I need X".
  2. So person A makes X for Q and turns it over to Q.
  3. Then person Q says "That's no good - it doesn't work."
  4. A says why not?
  5. Q says "because it doesn't get me Y."
  6. A says "Well you didn't ask for Y initially. You only asked for X. But now since you tell me you want Y, I can tell you that getting X will not get you Y and is, in fact, the wrong approach that you asked for. If you really want Y, you need to do Z"
  7. A does Z and hands it over to Q, who is now happy with the solution.
That happens all too often and is why we need the full context of what you're trying to do.
In your situation you're asking how to do something that three people are telling you doesn't make sense and in meaningless and useless. You never said why so now I'm assuming it may be one of those quirky homework problems that essentially has no real world use. Often times, and I'm not saying that it applies to you, but people ask questions to try to get people to do their homework problems for them but they don't want to admit it because people will then just give them hints instead of full solutions. This is because some professors use plagiarism detectors to see if the student just copied code from an online forum, and we don't want them to get into trouble. That's why we often see code posted as an image instead of text - so the plagiarism detectors won't find it. Again, not saying that's you. Despite asking for the need, you have not said it's your homework so we'll assume it's not, but we just don't know why someone would ask for such a weird thing. Nevertheless, DGM tried to give you something you mght be happy with. We want to give you Y so you can get Z but you keep saying you need X.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!