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

3 visualizaciones (últimos 30 días)
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

Respuesta aceptada

Yusuf Suer Erdem
Yusuf Suer Erdem el 15 de Nov. de 2021
Converting segmented RGB images into GRAYSCALE form is really good idea to process them.
  14 comentarios
mohammad nemat
mohammad nemat el 21 de Nov. de 2021
After a run of this code, I got PSNR=8.0089. I want to create function work like that imbinarize for making decisions and check each pixel one by one and replace 0 or 1 value for each one and get PSNR larger than 8.0089.
For example, I sent the previous code and I must use solution to do that.
For getting the maximum possible PSNR I must get the minimum MSE between RGB image and Binary image.
It's possible to suppose (0,1) or (0,255) in a generated image for each pixel
A = imread('peppers.png');
im2=imbinarize(A);
im2=uint8(im2);
b = psnr(A,im2);
DGM
DGM el 21 de Nov. de 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.

Iniciar sesión para comentar.

Más respuestas (3)

yanqi liu
yanqi liu el 18 de Nov. de 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 comentarios
yanqi liu
yanqi liu el 19 de Nov. de 2021
sir,may be use direct threshol,such as
img=imread('./test.png');
im2=img(:,:,1)>50;
b = PSNR(img,im2);

Iniciar sesión para comentar.


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

Iniciar sesión para comentar.


Image Analyst
Image Analyst el 20 de Nov. de 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 comentarios
mohammad nemat
mohammad nemat el 20 de Nov. de 2021
This is practice I must do. and I said my goal in the title and different situation.
What are you thinking about?
please let me know.
Image Analyst
Image Analyst el 21 de Nov. de 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.

Iniciar sesión para comentar.

Community Treasure Hunt

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

Start Hunting!

Translated by