MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

# Thread Subject: How to make image from the histogram?

 Subject: How to make image from the histogram? From: Mohd Farhan Date: 3 Nov, 2011 08:05:28 Message: 1 of 15 Lets suppose we have one image of 64x64 of 256-grey levels (0-7). & hence we we know its matrix. Now we make its histogram from imhist(). Now lets suppose we want to change some grey level pixel values (let of 200th & 210th & 220th & 255th levels) in histogram. eg: initially at 200th level there were 100pixels & at 210th level there were 10pixels & at 220th level there were 50pixels & at 255th level there were 200pixels.. & LET I CHANGED PIXEL VALUES TO OTHER VALUES. & now we want to again rebuilt the image to see its changes. HOW CAN I DO THIS?? THANKS IN ADVANCE..
 Subject: How to make image from the histogram? From: Nasser M. Abbasi Date: 3 Nov, 2011 08:16:06 Message: 2 of 15 On 11/3/2011 3:05 AM, Mohd Farhan wrote: > Lets suppose we have one image of 64x64 of 256-grey levels (0-7). > & hence we we know its matrix. > > Now we make its histogram from imhist(). > Now lets suppose we want to change some grey level pixel values > (let of 200th& 210th& 220th& 255th levels) in histogram. > eg: initially at 200th level there were 100pixels& > at 210th level there were 10pixels& > at 220th level there were 50pixels& > at 255th level there were 200pixels.. > > & LET I CHANGED PIXEL VALUES TO OTHER VALUES. > > & now we want to again rebuilt the image to see its changes. > HOW CAN I DO THIS?? > > THANKS IN ADVANCE.. I am not an image expert, so I might be missing something here. But a histogram just tells one a count of how many pixels at certain gray level(s). It does not tell one where these pixels are. If I tell you, there are 5 pixels with gray level 10, and 7 pixels at gray level 20. But do not tell you where those 5 pixels are located (i.e. their coordinates) how would one hope to construct an image just from the histogram? It seems to me that There is not enough information. Why do you think it is possible to reconstruct an image from just the histogram? --Nasser
 Subject: How to make image from the histogram? From: Mohd Farhan Date: 3 Nov, 2011 09:48:11 Message: 3 of 15 > I am not an image expert, so I might be missing something here. > > But a histogram just tells one a count of how many pixels at > certain gray level(s). > > It does not tell one where these pixels are. > > If I tell you, there are 5 pixels with gray level 10, and > 7 pixels at gray level 20. But do not tell you where those > 5 pixels are located (i.e. their coordinates) how would one > hope to construct an image just from the histogram? It seems > to me that There is not enough information. > > Why do you think it is possible to reconstruct an image > from just the histogram? > > --Nasser But we have image with us to know from where the histogram took that pixels.. we just have to compare the result as i think!! But how i don't know.. i.e. why i posted here, so that expert like "ImageAnalyst" can help.
 Subject: How to make image from the histogram? From: Nasser M. Abbasi Date: 3 Nov, 2011 10:10:15 Message: 4 of 15 On 11/3/2011 4:48 AM, Mohd Farhan wrote: >> I am not an image expert, so I might be missing something here. >> >> But a histogram just tells one a count of how many pixels at >> certain gray level(s). >> >> It does not tell one where these pixels are. >> >> If I tell you, there are 5 pixels with gray level 10, and >> 7 pixels at gray level 20. But do not tell you where those >> 5 pixels are located (i.e. their coordinates) how would one >> hope to construct an image just from the histogram? It seems >> to me that There is not enough information. >> >> Why do you think it is possible to reconstruct an image >> from just the histogram? >> >> --Nasser > But we have image with us to know from where the histogram took that pixels.. > we just have to compare the result as i think!! > But how i don't know.. > i.e. why i posted here, so that expert like "ImageAnalyst" can help. OK, I hope you get the answer from the experts. I am not an expert in image processing, but I just do not see how given a histogram, one can reconstruct that image back from it. There is simply no pixel locations information present. Histogram just tells one the distribution of pixel values, not the locations. But how knows, may be an expert can figure it out. good luck, --Nasser
 Subject: How to make image from the histogram? From: ImageAnalyst Date: 3 Nov, 2011 10:14:52 Message: 5 of 15 Maybe he's thinking of something like this imageArray(imageArray==200) = newValueFor200; imageArray(imageArray==210) = newValueFor210; imageArray(imageArray==220) = newValueFor220; imageArray(imageArray==255) = newValueFor255; You would have to supply actual values for newValueFor200 etc. - whatever values you want pixels with that graylevel to be in the changed image.
 Subject: How to make image from the histogram? From: Bjorn Gustavsson Date: 3 Nov, 2011 11:04:10 Message: 6 of 15 "Mohd Farhan " wrote in message ... > > I am not an image expert, so I might be missing something here. > > > > But a histogram just tells one a count of how many pixels at > > certain gray level(s). > > > > It does not tell one where these pixels are. > > > > If I tell you, there are 5 pixels with gray level 10, and > > 7 pixels at gray level 20. But do not tell you where those > > 5 pixels are located (i.e. their coordinates) how would one > > hope to construct an image just from the histogram? It seems > > to me that There is not enough information. > > > > Why do you think it is possible to reconstruct an image > > from just the histogram? > > > > --Nasser > But we have image with us to know from where the histogram took that pixels.. we just have to compare the result as i think!! > But how i don't know.. > i.e. why i posted here, so that expert like "ImageAnalyst" can help. > Maybe what you want to do can be done with the second output argument of histc. X = 255*rand(64,64); [N,index2bins] = histc(X,binlimits); X(index2bins==YourSelectedBinIndex) = TheNewValue; HTH, Bjeorn
 Subject: How to make image from the histogram? From: Mohd Farhan Date: 3 Nov, 2011 12:58:26 Message: 7 of 15 ImageAnalyst wrote in message <345b2296-7001-41a8-8dd0-3412b4a8a5d7@s30g2000yqd.googlegroups.com>... > Maybe he's thinking of something like this > > imageArray(imageArray==200) = newValueFor200; > imageArray(imageArray==210) = newValueFor210; > imageArray(imageArray==220) = newValueFor220; > imageArray(imageArray==255) = newValueFor255; > > You would have to supply actual values for newValueFor200 etc. - > whatever values you want pixels with that graylevel to be in the > changed image. But how to rebuilt image after shifing the grey levels? i.e. let suppose i shift the grey level 200 to 210. So the pixels of both the levels are added up & appers at 210. But how to see the image? what happened to image? I used this for shifting all values at grey-level 200, 220 & 255 to 0-grey-level: a = imread('D:/jug.jpg'); imageArray(I==200) = 0; imageArray(I==220) = 0; imageArray(I==255) = 0; imshow(I) BUT IT IS NOT SHOWING RESULTS! I DID MISTAKE SOMEWHERE?
 Subject: How to make image from the histogram? From: Mohd Farhan Date: 3 Nov, 2011 13:22:10 Message: 8 of 15 "Bjorn Gustavsson" wrote in message ... > Maybe what you want to do can be done with the second output argument of histc. > X = 255*rand(64,64); > [N,index2bins] = histc(X,binlimits); > X(index2bins==YourSelectedBinIndex) = TheNewValue; > > HTH, > Bjeorn I don't know why? but it is not working!
 Subject: How to make image from the histogram? From: Bjorn Gustavsson Date: 3 Nov, 2011 13:34:29 Message: 9 of 15 "Mohd Farhan " wrote in message ... > "Bjorn Gustavsson" wrote in message ... > > Maybe what you want to do can be done with the second output argument of histc. > > X = 255*rand(64,64); > > [N,index2bins] = histc(X,binlimits); > > X(index2bins==YourSelectedBinIndex) = TheNewValue; > > > > HTH, > > Bjeorn > I don't know why? but it is not working! > OK. Strange,i t sure works for me. If you dont tell me more I'll have a "somewhat" difficult time figuring out how to advice you further, this you must surely understand? In what way is it not working? What errors do you get? What does it do wrong? ...and so on...
 Subject: How to make image from the histogram? From: Steven_Lord Date: 3 Nov, 2011 14:13:04 Message: 10 of 15 "Mohd Farhan " wrote in message news:j8u35i\$d10\$1@newscl01ah.mathworks.com... > ImageAnalyst wrote in message > <345b2296-7001-41a8-8dd0-3412b4a8a5d7@s30g2000yqd.googlegroups.com>... >> Maybe he's thinking of something like this >> >> imageArray(imageArray==200) = newValueFor200; >> imageArray(imageArray==210) = newValueFor210; >> imageArray(imageArray==220) = newValueFor220; >> imageArray(imageArray==255) = newValueFor255; >> >> You would have to supply actual values for newValueFor200 etc. - >> whatever values you want pixels with that graylevel to be in the >> changed image. > But how to rebuilt image after shifing the grey levels? > i.e. let suppose i shift the grey level 200 to 210. So the pixels of both > the levels are added up & appers at 210. > But how to see the image? what happened to image? > > I used this for shifting all values at grey-level 200, 220 & 255 to > 0-grey-level: > a = imread('D:/jug.jpg'); imageArray(I==200) = 0; > imageArray(I==220) = 0; > imageArray(I==255) = 0; > imshow(I) > > BUT IT IS NOT SHOWING RESULTS! I DID MISTAKE SOMEWHERE? What is the name of the variable modified by your three middle lines of code? What is the name of the variable displayed by your IMSHOW call? Are the answers to those two questions the same? -- Steve Lord slord@mathworks.com To contact Technical Support use the Contact Us link on http://www.mathworks.com
 Subject: How to make image from the histogram? From: Mohd Farhan Date: 3 Nov, 2011 17:35:30 Message: 11 of 15 "Steven_Lord" wrote in message ... > > > "Mohd Farhan " wrote in message > news:j8u35i\$d10\$1@newscl01ah.mathworks.com... > > ImageAnalyst wrote in message > > <345b2296-7001-41a8-8dd0-3412b4a8a5d7@s30g2000yqd.googlegroups.com>... > >> Maybe he's thinking of something like this > >> > >> imageArray(imageArray==200) = newValueFor200; > >> imageArray(imageArray==210) = newValueFor210; > >> imageArray(imageArray==220) = newValueFor220; > >> imageArray(imageArray==255) = newValueFor255; > >> > >> You would have to supply actual values for newValueFor200 etc. - > >> whatever values you want pixels with that graylevel to be in the > >> changed image. > > But how to rebuilt image after shifing the grey levels? > > i.e. let suppose i shift the grey level 200 to 210. So the pixels of both > > the levels are added up & appers at 210. > > But how to see the image? what happened to image? > > > > I used this for shifting all values at grey-level 200, 220 & 255 to > > 0-grey-level: > > a = imread('D:/jug.jpg'); imageArray(I==200) = 0; > > imageArray(I==220) = 0; > > imageArray(I==255) = 0; > > imshow(I) > > > > BUT IT IS NOT SHOWING RESULTS! I DID MISTAKE SOMEWHERE? > > What is the name of the variable modified by your three middle lines of > code? > What is the name of the variable displayed by your IMSHOW call? > Are the answers to those two questions the same? > > -- > Steve Lord > slord@mathworks.com > To contact Technical Support use the Contact Us link on > http://www.mathworks.com it is showing same image without any change... I changed the pixels of gey level, this means image must change.. but it seems same!! Did i used correct program? Or what should i do? I did this: a = imread('D:/jug.jpg'); I = rgb2gray(a); imageArray(I==200) = 0; imageArray(I==220) = 0; imageArray(I==255) = 0; imshow(I)
 Subject: How to make image from the histogram? From: Mohd Farhan Date: 3 Nov, 2011 17:43:11 Message: 12 of 15 "Bjorn Gustavsson" wrote in message ... > "Mohd Farhan " wrote in message ... > > "Bjorn Gustavsson" wrote in message ... > > > Maybe what you want to do can be done with the second output argument of histc. > > > X = 255*rand(64,64); > > > [N,index2bins] = histc(X,binlimits); > > > X(index2bins==YourSelectedBinIndex) = TheNewValue; > > > > > > HTH, > > > Bjeorn > > I don't know why? but it is not working! > > > OK. Strange,i t sure works for me. If you dont tell me more I'll have a "somewhat" difficult time figuring out how to advice you further, this you must surely understand? > In what way is it not working? What errors do you get? What does it do wrong? ...and so on... I used ur formula like this: a = imread('D:/girl.jpg'); I = rgb2gray(a); [N,index2bins] = histc(X,0,120); X(index2bins==140,160) = TheNewValue; imshow(I) BUT IT IS SHOWING SAME IMAGE!! I DID SOME THING WRONG?
 Subject: How to make image from the histogram? From: ImageAnalyst Date: 3 Nov, 2011 19:18:13 Message: 14 of 15 It looks like he needs it spelled out real explicitly originalImage = imread('D:/jug.jpg'); % Convert to a grayscale image. grayImage = rgb2gray(originalImage); % Change pixels with value 200 in the grayscale image to 0 logicalMask = grayImage == 200; grayImage (logicalMask ) = 0; % Change pixels with value 220 in the grayscale image to 0 logicalMask = grayImage == 220; grayImage (logicalMask ) = 0; % Change pixels with value 255 in the grayscale image to 0 logicalMask = grayImage == 255; grayImage (logicalMask ) = 0; imshow(grayImage); Does that help?
 Subject: How to make image from the histogram? From: Mohd Farhan Date: 4 Nov, 2011 05:37:29 Message: 15 of 15 ImageAnalyst wrote in message <0e13152b-cbfc-460d-9203-4eaf7eb72064@hj4g2000vbb.googlegroups.com>... > It looks like he needs it spelled out real explicitly > > originalImage = imread('D:/jug.jpg'); > % Convert to a grayscale image. > grayImage = rgb2gray(originalImage); > > % Change pixels with value 200 in the grayscale image to 0 > logicalMask = grayImage == 200; > grayImage (logicalMask ) = 0; > > % Change pixels with value 220 in the grayscale image to 0 > logicalMask = grayImage == 220; > grayImage (logicalMask ) = 0; > > % Change pixels with value 255 in the grayscale image to 0 > logicalMask = grayImage == 255; > grayImage (logicalMask ) = 0; > > imshow(grayImage); > > Does that help? thanks it works..