How do I create a new image that has a stem function hist next to (i.e., side by side) an image?

I am new to matlab but have experience with other programming languages. Currently I am trying to create a new png or jpeg image that has all of my histograms and images in one "figure" but I am running into some issues.
Here is my code:
__________________
output=figure(1);
subplot(3,1,1); imshow(outputfinaltemp);
subplot(3,1,2); imshow(ipf);
subplot(3,1,3)
stem(0:255, opfhist);
__________________
output is a variable I assigned to refer to the final "figure", outputfinaltemp and ipf are just some images, and opfhist is one of many histograms that I am trying to include in this final figure. I am just working to get this one histogram to work but I am having some issues.
Note: I am trying to not use/rely on functions like hist or histograms because I am attempting to learn and work with more fundamental programming.
Is there a simple way I can combine multiple different graphs and images together without relying on premade programs?
Any help and direction would be greatly appreciated!

4 Comments

Such an image could be constructed entirely without relying on plotting tools (e.g. using histcounts() to generate an image programmatically), but programmatically generating that image would be a bit cumbersome. Programmatically adding text or axis labels would potentially be another inconvenience unless you have CVT or want to resort to using third-party tools.
That said, even if you used stem() to do the work of generating the stem plot, that doesn't mean you need to use the figure as a compositor for everything else. You could use stem(), capture the axes, and then programmatically composite the three images. Assuming the images are of mismatched size, one may be able to use imtile() or something (or just resize/pad as desired and then concatenate).
Depends how dedicated you are to avoiding the use of plot tools.
Hi yes, thank you for your thoughtful comment. While I do want to programmatically generate the histogram myself, I do not mind using more function based methods to organize and generate a "final image".
> opfhist is one of many histograms
Could you elaborate on this? I interpret a histogram to be a graphics object produced by the histogram function. Do you mean that it's a vector of bin counts produced, for example, by histcounts?
What problems are you having, specifically? An error message? An unexpected image?
> Is there a simple way I can combine multiple different graphs and images together
I'm also having trouble understanding this goal. Do you mean together on the same figure which appears to be what you're doing?
And as @DGM mentioned, what graphics functions are you trying to avoid (and why)?
To your first question, yes I believe so. Here is the code:
InputImage = ipf;
img_hist = zeros(p1,p2);
img_hist2 = zeros(p1,p2);
[rows,cols]=size(ipf);
for i = 1:rows % Rows of Input Image
for j = 1:cols % Colms of input image
img_hist(InputImage(i,j,1)+1) = img_hist(InputImage(i,j,1)+1)+1; %Bin Increment for occurrence
end
end
...
hist=figure(1);
subplot(2,1,1)
stem(0:255, img_hist);
subplot(2,1,2)
stem(0:255, img_hist2);
With ipf being a x by x uint8 image. img_hist2 is just a transformation that I made to img_hist (contrast stretching) but I chose to omit the code as I do not think it is pertinant and necessary to include. A simple, add(50) to img_hist, achieves more or less the same objective. Notably, this is a function that I nested inside a larger function so figure(1) is not physically present in the actual project but referenced.
Regarding your second question, I actually found out why my code was not working, I was using stem for a figure that had 2 separate histograms. I currently worked through the code to produce the end result that I wanted (although it was through a more clunky and less desirable means where I had to convert the figures into images that I had to recall back into matlab.
For your last inquiry, here is the image that I made using the method I described above. This is very much the end product that I would like to have (each histogram group is its own figure that was produced from a self-made function created from the code above). However, I was wondering if there was a simpler method to producing this figure without having to convert the histogram figures into a separate image.
This is partially for a HW assignment that I am working on. While it is not prohibited to utilize functions to create the histograms, I had desired to operate from a holistically ground-up perspective to create the histograms. However, manipulating the histograms to fit in a figure is something that I do not mind using a function for.
In short, I am wondering if there is a function that can be usedto create the image above while maintaining my method to create a histogram.
Thank you and I apologize for the lengthy message.

Sign in to comment.

Answers (0)

Categories

Asked:

on 12 Oct 2022

Edited:

on 12 Oct 2022

Community Treasure Hunt

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

Start Hunting!